#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n, q;
vector<int>components[1010];
int comps[1010];

int main()
{
    cin>>n>>q;
    for(int i=1; i<=n; i++){comps[i]=i; components[i].push_back(i);}
    while(q--)
    {
        int t; cin>>t;
        if(t==1)
        {
            int x, y; char c;
            cin>>x>>y>>c;
            if(comps[x]!=comps[y])
            {
                if(components[comps[x]].size()<components[comps[y]].size())swap(x, y);
                int p=comps[y];
                for(int i=0; i<components[p].size(); i++)
                {components[comps[x]].push_back(components[p][i]); comps[components[p][i]]=comps[x];}
            }
        }
        else
        {
            int x, y; cin>>x>>y;
            if(comps[x]==comps[y])cout<<1<<"\n";
            else cout<<0<<"\n";
        }
    }
    return 0;
}
/*5 6
1 1 2 a
1 2 3 a
2 1 3
2 2 3
1 3 4 a
2 1 4*/