#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 1010;
int n, q, par[N], sz[N];
int root(int v) {
    if (par[v] == v)
        return v;
    return par[v] = root(par[v]);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        cin >> n >> q;
        for (int i = 1;i <= n;i++) {
            par[i] = i;
            sz[i] = 1;
        }
        for (int i = 1;i <= q;i++) {
            int t;
            cin >> t;
            if (t == 1) {
                int u, v;
                char c;
                cin >> u >> v >> c;
                int x = root(u);
                int y = root(v);
                if (sz[x] < sz[y])
                    swap(x, y);
                par[y] = x;
                sz[x] += sz[y];
            }
            else {
                int u, v;
                cin >> u >> v;
                u = root(u);
                v = root(v);
                if (u == v)
                    cout << "1\n";
                else
                    cout << "0\n";
            }
        }
    }
    return 0;
}