#include <bits/stdc++.h>

using namespace std;

const int max_n = 1e3 + 5;

int parrent[max_n];
int sizes[max_n];


int get_parrent(int node){
    if (parrent[node] == node) return node;
    int p = get_parrent(parrent[node]);
    parrent[node] = p;
    return p;
}


void join(int a, int b){
    int pa = get_parrent(a);
    int pb = get_parrent(b);
    if (sizes[pa] < sizes[pb]){
        parrent[pa] = pb;
        sizes[pb] += sizes[pa];
    }
    else{
        parrent[pb] = pa;
        sizes[pa] += sizes[pb];
    }
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        sizes[i] = 1;
        parrent[i] = i;
    }
    int t, q, a, b;
    char c;
    cin >> q;
    for (int tc = 0; tc < q; tc++){
        cin >> t >> a >> b;
        if (t == 1){
            cin >> c;
            join(a, b);
        }
        else{
            if (get_parrent(a) == get_parrent(b)){
                cout << 1 << endl;
            }
            else cout << 0 << endl;
        }

    }
    return 0;
}
/*
5 6
2 1 2
1 1 3 a
2 1 3
1 3 4 a
2 1 4
2 2 4
*/