#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u);
void dfs1(int u);
void dfs2(int u);
const int mod = 1000000007;
const int N = 3e5, M = 50003;
//=======================
bitset<M> bit[M];
vi g[N], G[N], dag[N];
int cmp[N], vis[N];
int a[N];
int n, m, q, T;
vi top;
struct xxx{
int t, x, y;
void in(){
cin >> t >> x >> y;
}
}Q[N];
void read(){
int i;
cin >> n >> m;
ipgraph(m);
cin >> q;
Fo(i, 1, q+1){
Q[i].in();
int x = Q[i].x, y = Q[i].y;
if(Q[i].t == 1){
n++;
if(y == 0){
//x to n
g[x].pb(n);
G[n].pb(x);
}
else{
//n to x
g[n].pb(x);
G[x].pb(n);
}
}
}
}
void markSCC(){
int i;
clr(vis);
Fo(i, 1, n+1){
if(!vis[i]) dfs(i);
}
reverse(all(top));
clr(vis);
for(int u: top){
if(!vis[u]){
T++;
dfs1(u);
}
}
}
void compressSCC(){
int i;
Fo(i, 1, 1+n){
for(int v: g[i]){
if(cmp[i] == cmp[v]) continue;
dag[cmp[i]].pb(cmp[v]);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i,k,j;
read();
markSCC();
compressSCC();
//Now initialise bitsets for every component
Fo(i, 1, T+1){
bit[i] = 0;
bit[i].set(i, 1);
}
//Now fill in the bitsets
clr(vis);
Fo(i, 1, T+1){
if(!vis[i]) dfs2(i);
}
vi ans;
//Answering queries
Fo(i, 1, q+1){
if(Q[i].t == 2){
ans.pb(bit[cmp[Q[i].x]].test(cmp[Q[i].y]));
}
}
for(int x: ans) cout << (x?"Yes":"No") << endl;
return 0;
}
void ipgraph(int m){
int i, u, v;
fo(i, m){
cin>>u>>v;
u++, v++;
g[u-1].pb(v-1);
G[v-1].pb(u-1);
}
}
void dfs(int u){
vis[u] = 1;
for(int v:g[u]){
if (vis[v]) continue;
dfs(v);
}
top.pb(u);
}
void dfs1(int u){
cmp[u] = T;
vis[u] = 1;
for(int v:G[u]){
if (vis[v]) continue;
dfs1(v);
}
}
void dfs2(int u){
vis[u] = 1;
for(int v:dag[u]){
if (vis[v]) continue;
dfs2(v);
}
for(int v:dag[u]){
bit[u] |= bit[v];
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgZ2MgZ2V0Y2hhcl91bmxvY2tlZAojZGVmaW5lIGZvKGksbikgZm9yKGk9MDtpPG47aSsrKQojZGVmaW5lIEZvKGksayxuKSBmb3IoaT1rO2s8bj9pPG46aT5uO2s8bj9pKz0xOmktPTEpCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgc2koeCkJc2NhbmYoIiVkIiwmeCkKI2RlZmluZSBzbCh4KQlzY2FuZigiJWxsZCIsJngpCiNkZWZpbmUgc3MocykJc2NhbmYoIiVzIixzKQojZGVmaW5lIHBpKHgpCXByaW50ZigiJWRcbiIseCkKI2RlZmluZSBwbCh4KQlwcmludGYoIiVsbGRcbiIseCkKI2RlZmluZSBwcyhzKQlwcmludGYoIiVzXG4iLHMpCiNkZWZpbmUgcGIgcHVzaF9iY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