#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template using V=vector; template using VV=V>; //B(n,V(n)) int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,m; cin>>n>>m; V P(n); V> wor(n),fri(n); rep(i,n){ cin>>P[i]; P[i]--; wor[P[i]].set(i); } rep(i,m){ int a,b; cin>>a>>b; a--,b--; fri[a].set(b); fri[b].set(a); } int q; cin>>q; rep(i,q){ int x,y; cin>>x>>y; x--,y--; if(P[x]==P[y]){ cout<<"No\n"; } else{ if((wor[P[y]]&fri[x]).any()){ cout<<"Yes\n"; wor[P[x]].reset(x); P[x]=P[y]; wor[P[x]].set(x); } else cout<<"No\n"; } } return 0; }