#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define st first
#define nd second
using namespace std;
typedef pair<int,int> ii;
vector <int> dsu(1005,-1);
int Find(int a){return (dsu[a]<0)?a:dsu[a]=Find(dsu[a]);}
void Join(int a,int b){
a=Find(a);b=Find(b);
if(a==b)return;
else{
if(a>b)swap(a,b);
dsu[b]+=dsu[a];dsu[a]=b;
}
}
int main(){
ios_base::sync_with_stdio(false);
freopen("no112b.inp","r",stdin);
freopen("no112b.out","w",stdout);
int n,m;scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
int u,v;scanf("%d%d",&u,&v);
Join(u,v);
}
int q;scanf("%d",&q);
while(q--){
int t,u,v;
scanf("%d%d%d",&t,&u,&v);
if(t==1){
if(Find(u)==Find(v))printf("1");
else printf("0");
}
else{
Join(u,v);
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgc3QgZmlyc3QKI2RlZmluZSBuZCBzZWNvbmQKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBwYWlyPGludCxpbnQ+IGlpOwp2ZWN0b3IgPGludD4gZHN1KDEwMDUsLTEpOwppbnQgIEZpbmQoaW50IGEpe3JldHVybiAoZHN1W2FdPDApP2E6ZHN1W2FdPUZpbmQoZHN1W2FdKTt9CnZvaWQgSm9pbihpbnQgYSxpbnQgYil7CiAgICBhPUZpbmQoYSk7Yj1GaW5kKGIpOwogICAgaWYoYT09YilyZXR1cm47CiAgICBlbHNlewogICAgICAgIGlmKGE+Yilzd2FwKGEsYik7CiAgICAgICAgZHN1W2JdKz1kc3VbYV07ZHN1W2FdPWI7CiAgICB9Cn0KaW50IG1haW4oKXsKCWlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgZnJlb3Blbigibm8xMTJiLmlucCIsInIiLHN0ZGluKTsKICAgIGZyZW9w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