#include<bits/stdc++.h>
using namespace std;
long long N,Q,T,u,v;
char c;
vector<int>G[1009];
vector<char>Gc[1009];
bool uspeh;
int otac[1009],dubina[1009];
int otacf(int a){
  while(otac[a]!=a){
    otac[a]=otac[otac[a]];
    a=otac[a];
  }
  return a;
}
void join(int a,int b){
  int x=otacf(a);
  int y=otacf(b);
  if(dubina[x]>dubina[y])otac[y]=x;
  if(dubina[x]<dubina[y])otac[x]=y;
  if(dubina[x]==dubina[y]){
    otac[x]=y;
    dubina[y]++;
  }
}
int main(){
  //freopen("C1.txt","r",stdin);
  ios_base::sync_with_stdio(false);
  cin>>N>>Q;
  for(int i=1; i<=N; i++)otac[i]=i;
  for(int i=1; i<=N; i++)dubina[i]=0;
  string s,x,y;
  s.resize(N+2);
  bool spec=true;
  while(Q--){
    cin>>T>>u>>v;
    if(T==1){
      cin>>c;
      if(v!=u+1)spec=false;
      s[u]=c;
      if(otacf(u)!=otacf(v))join(u,v);
    }
    if(T==2){
      if(otacf(u)==otacf(v)){
        if(!spec)cout<<"1\n";
        else{
          x=s.substr(u,v-u+1);
          y=x;
          reverse(x.begin(),x.end());
          if(x==y)cout<<"1\n";
          else cout<<"0\n";
        }
      }
      else cout<<"0\n";
    }
  }
  return 0;
}