#include using namespace std; const int N_MAX = 20000; int main() { int N, M; cin >> N >> M; vector world_of(N); vector> in_world(N); for (int i = 0; i < N; i++) { cin >> world_of[i]; world_of[i]--; in_world[world_of[i]][i] = true; } vector> friend_of(N); for (int i = 0; i < M; i++) { int A, B; cin >> A >> B; A--; B--; friend_of[A][B] = friend_of[B][A] = true; } int Q; cin >> Q; for (int t = 0; t < Q; t++) { int X, Y; cin >> X >> Y; X--; Y--; if (world_of[X] != world_of[Y] && (friend_of[X] & in_world[world_of[Y]]).any()) { cout << "Yes\n"; in_world[world_of[X]][X] = false; world_of[X] = world_of[Y]; in_world[world_of[X]][X] = true; } else { cout << "No\n"; } } }