#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #define rep(i,n) for(int i=0;i<(n);i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)(x).size()) #define pb push_back using ll = long long; using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> N >> M; vector> P(N); vector> B(N); vector W(N); rep(i,N){ int a; cin >> a; a--; W[i] = a; P[a].set(i); } rep(i,M){ int a,b; cin >> a >> b; a--; b--; if(a==b) continue; B[a].set(b); B[b].set(a); } int Q; cin >> Q; while(Q--){ int x,y; cin >> x >> y; x--; y--; if(W[x]==W[y]) cout << "No\n"; else{ if((P[W[y]]&B[x]).any()){ cout << "Yes\n"; P[W[x]].reset(x); P[W[y]].set(x); W[x] = W[y]; } else cout << "No\n"; } } return 0; }