#include <iostream>
#include <vector>
#include <queue>

using namespace std;

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

    int n, q;
    cin >> n >> q;

    vector<vector<int> > listaPovezanosti(n+1);
    for(int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if(t == 1) {
            int u, v;
            char c;
            cin >> u >> v >> c;
            listaPovezanosti[u].push_back(v);
            listaPovezanosti[v].push_back(u);
        }else{
            int u, v;
            cin >> u >> v;

            bool posecen[n+1] = {};
            queue<int> red;
            red.push(u);

            while(!red.empty()) {
                int cvor = red.front();
                red.pop();

                posecen[cvor] = true;
                if(cvor == v)
                    break;

                for(int i = 0; i < listaPovezanosti[cvor].size(); i++) {
                    int cvor1 = listaPovezanosti[cvor][i];
                    if(!posecen[cvor1])
                        red.push(cvor1);
                }
            }
            if(posecen[v])
                cout << true << '\n';
            else
                cout << false << '\n';
        }
    }


    return 0;
}