#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <utility>
#define pb push_back
#define mp make_pair
#define ft first
#define nd second
#define init(x,n,y) x.assign(n,y);
#define Kagami(f) f.end()
#define Natsu(f) f.begin()
#define NatsuKagami(f) f.begin(),f.end()
#define low(f,x) lower_bound(f.begin(),f.end(),x)
#define hi(f,x) upper_bound(f.begin(),f.end(),x)
#define poi(a,x,y) for(int a = x; a < y; ++a)
#define meow(a,x,y) for (int a = x; a >= y; --a)
using namespace std;
typedef vector<int> vi;
int n,m;
int q, t, u, v;
vi dsu; int setCount;
int find(int i) {return dsu[i]<0?i:dsu[i]=find(dsu[i]);}
bool same(int i, int j) {return find(i)==find(j);}
void join(int i, int j) {
if (same(i,j)) return; --setCount, i = find(i), j = find(j);
if (dsu[i]>dsu[j]) swap(i,j);
dsu[i]+=dsu[j]; dsu[j]=i;
}
void initDsu(int size) {
setCount = size; init(dsu,size,-1);
}
int main() {
ios_base::sync_with_stdio(false);
freopen("no112b.inp","r",stdin);
freopen("no112b.out","w",stdout);
scanf("%d",&n); initDsu(n+1);
scanf("%d",&m); while (m--) {scanf("%d%d",&u,&v); join(u,v);}
scanf("%d",&q);
while (q--) {
scanf("%d%d%d",&t,&u,&v);
if (t==1) printf("%d",(same(u,v)?1:0));
else join(u,v);
}
printf("\n");
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxmdW5jdGlvbmFsPgojaW5jbHVkZSA8dXRpbGl0eT4KI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBmdCBmaXJzdAojZGVmaW5lIG5kIHNlY29uZAojZGVmaW5lIGluaXQoeCxuLHkpIHguYXNzaWduKG4seSk7CiNkZWZpbmUgS2F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