#include #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--; #define VL vector #define VVL vector> 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); VL C(N); REP(i, M) { C[A[i]]++; C[B[i]]++; } VVL 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]); } unordered_multiset s; REP(i, N) { if (C[i] < sqm) continue; for (auto& v : few[i]) s.insert(i * N + P[v]); } ll Q; cin >> Q; while (Q--) { ll X, Y; cin >> X >> Y; X--; Y--; if (P[X] == P[Y]) { cout << "No\n"; continue; } ll cnt = 0; for (auto& v : many[X]) { cnt += P[v] == P[Y]; if (cnt) break; } if (C[X] < sqm) { for (auto& v : few[X]) { cnt += P[v] == P[Y]; if (cnt) break; } } else if (cnt == 0) { cnt += s.find(X*N+P[Y]) != s.end(); } if (cnt) { cout << "Yes\n"; if (C[X] < sqm) { for (auto& v : many[X]) { s.erase(s.find(v* N + P[X])); s.insert(v* N + P[Y]); } } P[X] = P[Y]; } else { cout << "No\n"; } } return 0; }