#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1e3 + 100;

int n,q;
vector<int> nodes[MAX_N]; // 1. index 2. spojeni na slovo
                              //   MAX_N         27 slova

bool possible(int a, int b)
{
    bool bio[MAX_N];

    queue<int> next;
    next.push(a);
    while(!next.empty())
    {
        int current = next.front();

        if(current == b)
        {
            return true;
        }

        bio[current] = true;
        next.pop();

        for(int i=0;i<nodes[current].size();i++)
        {
            if(!bio[nodes[current][i]])
            {
                next.push(nodes[current][i]);
            }
        }


    }

    return false;

}


int main()
{
    // Ulaz
    cin>>n>>q;

    // Obrada + Izlaz
    for(int i=0;i<q;i++)
    {
        int t;
        cin>>t;

        if(t == 1)
        {
            int u,v;
            char c;
            cin>>u>>v>>c;

            nodes[u].push_back(v);
            nodes[v].push_back(u);
        }
        else
        {
            int u,v;
            cin>>u>>v;

            cout<<possible(u,v)<<endl;
        }
    }

    return 0;
}