#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define MAXN 300010

using namespace std;

vector <ll> DSU(MAXN);
vector <ll> SIZE(MAXN);

ll root(ll X)
{
    if(X == DSU[X]) return X;
    return DSU[X] = root(DSU[X]);
}

void spoji(ll X, ll Y)
{
    X = root(X);
    Y = root(Y);
    if(X == Y) return;
    if(SIZE[X] < SIZE[Y]) swap(X, Y);
    DSU[Y] = X;
    SIZE[X] += SIZE[Y];
    SIZE[Y] = 0;
}

bool pal(string s)
{
    string t = s;
    reverse(t.begin(), t.end());
    return (s == t);
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    for(int i = 0; i < MAXN; i++) {DSU[i] = i; SIZE[i] = 1;}
    ll N, Q, X, Y, i = 0;
    vector <pair < pair<ll, ll>, pair <ll, char> > > sve(MAXN);
    ll tip;
    char ch;
    cin >> N >> Q;
    bool da_li = true;
    while(Q--)
    {
        cin >> tip;
        if(tip == 1)
        {
            cin >> X >> Y >> ch;
            if(ch != 'a') da_li = false;
            sve[i].first.first = tip;
            sve[i].first.second = X;
            sve[i].second.first = Y;
            sve[i].second.second = ch;
        }
        else
        {
            cin >>X >> Y;
            sve[i].first = {tip, X};
            sve[i].second = {Y, '#'};
        }
        i++;
    }
    if(da_li)
    {
        for(int k = 0; k < i; k++)
        {
            if(sve[k].first.first == 1)
            {
                spoji(sve[k].first.second, sve[k].second.first);
            }
            else
            {
                if(root(sve[k].first.second) != root(sve[k].second.first)) cout << 0 << endl;
                else cout << 1 << endl;
            }
        }
    }
    else
    {
        string s = "";
        for(int i = 0; i < MAXN; i++) s += " ";
        for(int k = 0; k < i; k++)
        {
            if(sve[k].first.first == 1)
            {
                ll L = sve[k].first.second;
                ll R = sve[k].second.first;
                s[L - 1] = sve[k].second.second;
            }
            else
            {
                ll L = sve[k].first.second;
                ll R = sve[k].second.first;
                L--;
                R -= 2;
                string s1 = s.substr(L, R - L + 1);
                if(pal(s1)) cout << 1 << endl;
                else cout << 0 << endl;
            }
        }
    }
    return 0;
}
/**
5 6
1 1 2 a
1 2 3 a
2 1 3
2 2 3
1 3 4 a
2 1 4
**/