#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define pb push_back
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int maxN = 1009;
vector<vector<int>> g(maxN);
vector<int> boja(maxN, -1);
int main(){
    ios;
    int n, q;
    cin>>n>>q;
    for(int i = 1;i<=n;i++)boja[i]=i;
    while(q--){
        int tip;
        cin>>tip;
        if(tip==1){
            int u, v;
            char c;
            cin>>u>>v>>c;
            int b1 = boja[u];
            int b2 = boja[v];
            for(int i = 1;i<=n;i++){
                if(boja[i]==b2)boja[i]=b1;
            }
        }
        else{
            int u, v;
            cin>>u>>v;
            if(boja[u]==boja[v])cout<<1<<endl;
            else cout<<0<<endl;
        }
    }


}