#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9;
const ll LINF=1e18;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define pb push_back

void PRINT(int x) {cerr << x;}
void PRINT(ll x) {cerr << x;}
void PRINT(double x) {cerr << x;}
void PRINT(char x) {cerr << '\'' << x << '\'';}
void PRINT(string x) {cerr << '\"' << x << '\"';}
void PRINT(bool x) {cerr << (x ? "true" : "false");}

template<typename T,typename V>
void PRINT(pair<T,V>& x){
    cerr<<"{";
    PRINT(x.fi);
    cerr<<",";
    PRINT(x.se);
    cerr<<"}";
}
template<typename T>
void PRINT(T &x){
    int id=0;
    cerr<<"{";
    for(auto _i:x){
        cerr<<(id++ ? "," : "");
        PRINT(_i);
    }
    cerr<<"}";
}
void _PRINT(){
    cerr<<"]\n";
}
template<typename Head,typename... Tail>
void _PRINT(Head h,Tail... t){
    PRINT(h);
    if(sizeof...(t)) cerr<<", ";
    _PRINT(t...);
}

#define Debug(x...) cerr<<"["<<#x<<"]=["; _PRINT(x)

const int mxN=1000;
int siz[mxN+1],dsu[mxN+1];

int Root(int u){
    return (dsu[u]==u ? u : dsu[u]=Root(dsu[u]));
}

void Connect(int u,int v){
    u=Root(u),v=Root(v);
    if(u==v) return;
    if(siz[u]<siz[v]) swap(u,v);
    siz[u]+=siz[v];
    dsu[v]=u;
}

int main(){
    int N; cin>>N;
    int Q; cin>>Q;
    fill(siz+1,siz+1+N,1);
    iota(dsu+1,dsu+1+N,1);
    while(Q--){
        int t; cin>>t;
        if(t==1){
            int u,v; cin>>u>>v;
            Connect(u,v);
            char c; cin>>c; if(c!='a') return 0;
        }
        else{
            int u,v; cin>>u>>v;
            cout<<(Root(u)==Root(v))<<endl;
        }
    }
    return 0;
}