//Dedicated to my love, ivaziva
#include "bits/stdc++.h"
#define dbg(x) cerr << #x << ": " << x << endl;
#define ll long long
#define pb push_back
#define all(a) a.begin(),a.end()
#define si(s) (ll)(s.size())
using namespace std;
#define maxn 1005


int n, q;
int par[maxn];

int get(int x) {
	return x ^ par[x] ? par[x] = get(par[x]) : x;
}

void unite(int u, int v) {
	u = get(u);
	v = get(v);
	if(u != v) par[v] = u;
}


signed main(){
	ios_base::sync_with_stdio(false);
	cout.tie(0); cin.tie(0); cerr.tie(0);

	cin >> n >> q;
	for(int i = 1; i <= n; i++) par[i] = i;
    while(q--) {
        int tp;
        cin >> tp;
        if(tp == 1) {
            int u, v;
            char c;
            cin >> u >> v >> c;
            unite(u, v);
        } else {
            int u, v;
            cin >> u >> v;
            if(get(u) == get(v)) {
                cout << 1 << '\n';
            }
            else cout << 0 << '\n';
        }
    }
	return 0;
}