#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
vector <long long> g[100001];
bool pos[100001];
void dfs(long long d)
{
    if (pos[d]) return;
    pos[d] = true;
    for (auto u : g[d])
    {
        dfs(u);
    }
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long long n, q, i, t, a, b;
    char c;
    cin >> n >> q;
    while (q--)
    {
        cin >> t >> a >> b;
        if (t == 1)
        {
            g[a].push_back(b);
            g[b].push_back(a);
            cin >> c;
            continue;
        }
        for (i = 1; i <= n; i++)
        {
            pos[i] = false;
        }
        dfs(a);
        if (pos[b])
        {
            cout << 1 << endl;
        }
        else cout << 0 << endl;
    }
    return 0;
}