#include <bits/stdc++.h>
//#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"

using namespace std;

//const int MAXN = 1e3+5;
vector<int> parents;
vector<int> nmcmp;
struct str{int t, a,b;char c;};

int findparent(int x)
{
    if(parents[x]!=x)x = findparent(parents[x]);
    return parents[x];
}

void connectCMP(int a, int b)
{
    int r1 = findparent(a);
    int r2 = findparent(b);
    if(nmcmp[r1] > nmcmp[r2])
    {
        parents[r2] = r1;
        nmcmp[r1] = nmcmp[r1]+nmcmp[r2];
        nmcmp[r2] = nmcmp[r1];
    }
    else
    {
        parents[r1] = r2;
        nmcmp[r2] = nmcmp[r1]+nmcmp[r2];
        nmcmp[r1] = nmcmp[r2];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    int n,q;
    cin >> n >> q;
    vector<str>querys(q);
    bool moze = true;
    for(int i=0; i<q; i++)
    {
        int t;cin >> t;
        if(t== 1)
        {
            int a,b;char c;
            cin >> a >> b >> c;
            if(c!='a')moze= 0;
            querys[i] = {t,a,b,c};
        }
        else
        {
            int a, b;
            cin >> a >> b;
            querys[i] = {t,a,b,'0'};
        }
    }
    if(moze)
    {
        parents = vector<int>(n+1);
        nmcmp = vector<int>(n+1);
        for(int i=1; i<=n; i++){parents[i] = i;nmcmp[i] = 1;}
       for(int i=0; i<q; i++)
        {
            str tr = querys[i];
            int t = tr.t;
            if(t== 1)
            {
                int a = tr.a;
                int b = tr.b;
                connectCMP(a,b);
            }
            else
            {
                int a = tr.a;
                int b = tr.b;
                //findparent(a);
                //findparent(b);
                if(findparent(a) == findparent(b))cout <<1 <<endl;
                else cout << 0 << endl;
            }
        }
    }
    else
    {
        vector<vector<int>> niz(n+1, vector<int>(26, 0));
        for(int i=0; i<q; i++)
        {
            str tr = querys[i];
            int t = tr.t;
            if(t== 1)
            {
                int a = tr.a;
                int b = tr.b;
                char c = tr.c;
                niz[a][c-'a']++;
            }
            else
            {
                int a = tr.a;
                int b = tr.b-1;
                //findparent(a);
                //findparent(b);
                bool moze = true;
                while(a< b)
                {
                    bool tr = false;
                    for(int i=0; i<26; i++)
                    {
                        if(niz[a][i] > 0 && niz[b][i]>0)tr = 1;
                        if(tr)break;
                    }
                    moze = tr;
                    if(!moze)break;
                    a++;b--;
                }
                if(moze)cout  << 1 << endl;
                else cout << 0 << endl;
            }
        }

    }

}