#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define maxn 1010

using namespace std;
typedef long long ll;

int n,q,qtype,u,v,p[maxn], siz[maxn];
char c;

void makeset(int v)
{
    p[v]=v;
    siz[v]=1;
}

int findset(int v)
{
    if(p[v]==v) return v;
    return p[v]=findset(p[v]);
}

void unionset(int a, int b)
{
    a=findset(a);
    b=findset(b);
    if(a!=b){
        if(siz[a]>siz[b]) swap(a,b);
        p[a]=b;
        siz[b]+=siz[a];
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    for(int i=1; i<=n; i++){
        makeset(i);
    }
    while(q--){
        cin >> qtype;
        if(qtype==1){
            cin >> u >> v >> c;
            unionset(u,v);
        }
        else{
            cin >> u >> v;
            if(findset(u)==findset(v)) cout << 1 << "\n";
            else cout << 0 << "\n";
        }
    }
}