#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vectorP(N); for(int i = 0; i < N; i++) { cin >> P[i]; P[i]--; } vector>road1(N); vector>road2(N); for(int i = 0; i < M; i++) { int A,B; cin >> A >> B; A--; B--; road1[A].push_back(B); road1[B].push_back(A); } int B = 334; vector>cnt(N); for(int i = 0; i < N; i++) { if(road1[i].size() >= B) { cnt[i].resize(N); } } for(int i = 0; i < N; i++) { for(int j:road1[i]) { if(road1[j].size() >= B) { road2[i].push_back(j); cnt[j][P[i]]++; } } } int Q; cin >> Q; while(Q--) { int X,Y; cin >> X >> Y; X--; Y--; if(P[X] == P[Y]) { cout << "No" << "\n"; continue; } if(road1[X].size() >= B) { if(cnt[X][P[Y]]) { cout << "Yes" << "\n"; for(int i:road2[X]) { cnt[i][P[X]]--; cnt[i][P[Y]]++; } P[X] = P[Y]; } else { cout << "No" << "\n"; } } else { bool f = false; for(int i:road1[X]) { if(P[i] == P[Y]) f = true; } if(f) { cout << "Yes" << "\n"; for(int i:road2[X]) { cnt[i][P[X]]--; cnt[i][P[Y]]++; } P[X] = P[Y]; } else { cout << "No" << "\n"; } } } }