#include using namespace std; int main() { int MN = 2e4; int N, M;cin >> N >> M; vector> S(N); vector> T(N); vector P(N); for (int i = 0;i < N;i++) { cin >> P[i]; P[i]--; T[P[i]].set(i); } for (int i = 0;i < M;i++) { int a, b;cin >> a >> b; a--;b--; S[a].set(b); S[b].set(a); } int Q;cin >> Q; while (Q--) { int x, y;cin >> x >> y;x--;y--; if (P[x] == P[y]) { cout << "No" << endl; continue; } int px = P[x];int py = P[y]; auto res = S[x] & T[py]; if (!res.any()) { cout << "No" << endl; continue; } T[py].set(x); T[px].reset(x); P[x] = py; cout << "Yes" << endl; } }