#include <bits/stdc++.h>

using namespace std;

#define MAXN 1010

long long n,q;
vector<pair<pair<long long,long long>,char> > upiti;
long long parent[MAXN];
long long siz[MAXN];
long long seg2[MAXN*4];

long long get(long long node)
{
    if (parent[node]==node) return node;
    else return get(parent[node]);
}

void unite(long long node1,long long node2)
{
    node1=get(node1),node2=get(node2);
    if (node1!=node2)
    {
        if (siz[node1]<siz[node2]) swap(node1,node2);
        parent[node2]=node1;siz[node1]+=siz[node2];
    }
}

void build2(long long node,long long l,long long r)
{
    if (l==r) seg2[node]=0;
    else
    {
        long long mid=(l+r)/2;
        build2(2*node,l,mid);
        build2(2*node+1,mid+1,r);
        seg2[node]=seg2[2*node]+seg2[2*node+1];
    }
}

void update2(long long node,long long l,long long r,long long pos,long long val)
{
    if (l==r) seg2[node]=val;
    else
    {
        long long mid=(l+r)/2;
        if (pos<=mid) update2(2*node,l,mid,pos,val);
        else update2(2*node+1,mid+1,r,pos,val);
        seg2[node]=seg2[2*node]+seg2[2*node+1];
    }
}

long long query2(long long node,long long l,long long r,long long a,long long b)
{
    if (a>b) return 0;
    if (l==a and r==b) return seg2[node];
    long long mid=(l+r)/2;
    return query2(2*node,l,mid,a,min(b,mid))+query2(2*node+1,mid+1,r,max(a,mid+1),b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>q;
    for (long long i=1;i<=n;i++) parent[i]=i;
    for (long long i=1;i<=n;i++) siz[i]=1;
    long long bra=0;
    bool da=true;
    for (long long i=1;i<=q;i++)
    {
        long long t;cin>>t;
        if (t==1)
        {
            long long a,b;cin>>a>>b;
            if (a==b+1) swap(a,b);
            char c;cin>>c;
            if (b!=a+1) da=false;
            upiti.push_back({{a,b},c});
            if (c=='a') bra++;
        }
        if (t==2)
        {
            long long a,b;cin>>a>>b;bra++;
            upiti.push_back({{a,b},' '});
        }
    }
    if (bra==q)
    {
        ///1.subtask-proslo
        for (long long i=0;i<q;i++)
        {
            long long a=upiti[i].first.first;
            long long b=upiti[i].first.second;
            char c=upiti[i].second;
            if (c!=' ') {unite(a,b);continue;}
            a=get(a);b=get(b);
            if (a==b) cout<<1<<endl;
            else cout<<0<<endl;
        }
        return 0;
    }
    if (da)
    {
        ///2.subtask-nije proslo nmp zasto voli
        build2(1,1,n-1);
        string ans;
        for (long long i=1;i<=n+10;i++) ans.push_back(' ');
        for (long long i=0;i<q;i++)
        {
            long long a=upiti[i].first.first;
            long long b=upiti[i].first.second;
            char s=upiti[i].second;
            if (s!=' ') {ans[a]=s;update2(1,1,n,a,1);continue;}
            long long br=query2(1,1,n,a,b-1);
            if (br!=b-a) {cout<<0<<endl;continue;}
            string s1=ans.substr(a,b-a);
            string s2=s1;reverse(s1.begin(),s1.end());
            if (s1==s2) cout<<1<<endl;
            else cout<<0<<endl;
        }
        return 0;
    }
    return 0;
}