#include <bits/stdc++.h>
#define MAXN 200010

using namespace std;

typedef  long long ll;

ll n, q;
ll a[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> q;
    ll t, u, v;
    char c;
    for(int i = 1; i <= n; i++) a[i] = i;
    while(q--)
    {
        cin >> t >> u >> v;
        if(t == 1)
        {
            cin >> c;
            ll j = a[u];
            ll k = a[v];
            for(int i = 1; i <= n; i++) if(a[i] == k) a[i] = j;
        }
        else
        {
            if(a[u] == a[v]) cout << "1\n";
            else cout << "0\n";
        }
    }
    return 0;
}