#include #include #include #include #include using namespace std; using ll = long long; #define FOR(i, a, b) for(ll i=(a); i<(b);i++) #define REP(i, n) for(ll i=0; i<(n);i++) #define INC(a) for(auto& v:a)v++; #define DEC(a) for(auto& v:a)v--; template vector read(size_t n) { vector ts(n); for (size_t i = 0; i < n; i++) cin >> ts[i]; return ts; } template void read_tuple_impl(TV&) {} template void read_tuple_impl(TV& ts) { get(ts).emplace_back(*(istream_iterator(cin))); read_tuple_impl(ts); } template decltype(auto) read_tuple(size_t n) { tuple...> ts; for (size_t i = 0; i < n; i++) read_tuple_impl(ts); return ts; } int main() { ll N, M; cin >> N >> M; auto P = read(N); DEC(P); auto [A, B] = read_tuple(M); DEC(A); DEC(B); vector C(N); REP(i, M) { C[A[i]]++; C[B[i]]++; } vector> few(N), many(N); ll sqm = sqrt(M); REP(i, M) { if (C[B[i]] < sqm) few[A[i]].push_back(B[i]); else many[A[i]].push_back(B[i]); if (C[A[i]] < sqm) few[B[i]].push_back(A[i]); else many[B[i]].push_back(A[i]); } vector> fewC(N); REP(i, N) { if (C[i] < sqm) continue; fewC[i].resize(N); for (auto& v : few[i]) fewC[i][P[v]]++; } ll Q; cin >> Q; auto findFriend = [&](ll X, ll Y) { if (P[X] == P[Y]) { return false; } for (auto& v : many[X]) { if (P[v] == P[Y]) return true; } if (C[X] < sqm) { for (auto& v : few[X]) { if (P[v] == P[Y]) return true; } return false; } else { return fewC[X][P[Y]] > 0; } }; while (Q--) { ll X, Y; cin >> X >> Y; X--; Y--; if (findFriend(X, Y)) { cout << "Yes\n"; if (C[X] < sqm) { for (auto& v : many[X]) { fewC[v][P[X]]--; fewC[v][P[Y]]++; } } P[X] = P[Y]; } else { cout << "No\n"; } } return 0; }