#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pii pair<int,int>

using namespace std;

int mark[1010];
vector<pair<int,char>>graf[1010];

bool dfs(int nod,int kraj,string dist,int col){
    if(mark[nod]==col)return false;
    //cerr<<"nod = "<<nod<<" kraj = "<<kraj<<endl;
    if(nod==kraj){
        int l=0,r=dist.size()-1;
        //cerr<<dist<<endl;
        while(l<r){
            if(dist[l]!=dist[r])return false;
            l++;r--;
        }
        return true;
    }
    mark[nod]=col;
    for(auto i:graf[nod]){
        //cerr<<"Pretrazujemo nod = "<<i.fi<<" ima vezu = "<<i.se<<endl;
        bool t=dfs(i.fi,kraj,dist+i.se,col);
        if(t==true)return true;
    }
    return false;
}

int main()
{
    speed;
    int n,q,col=1;
    cin>>n>>q;
    while(q--){
        int c;
        cin>>c;
        if(c==1){
            int u,v;
            char k;
            cin>>u>>v>>k;
            graf[u].push_back({v,k});
            graf[v].push_back({u,k});
        }
        else{
            int u,v;
            cin>>u>>v;
            //cerr<<"DFS____________"<<endl;
            cout<<dfs(u,v,"",col++)<<endl;
        }
    }
    return 0;
}
/*
5 6
1 1 2 a
2 2 1
1 2 3 b
1 3 4 a
2 1 4
2 2 4

1
1
0
*/