#include using namespace std; using i64 = int64_t; constexpr i64 mod = 998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector p(n + 1); for (int i = 1; i <= n; i += 1) { cin >> p[i]; } vector> g(n + 1), sg(n + 1); vector> adj(n + 1); int sn = 500; for (int i = 0, x, y; i < m; i += 1) { cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } for (int i = 1; i <= n; i += 1) { if (g[i].size() > sn) { for (int j : g[i]) { sg[j].push_back(i); adj[i].insert(p[j]); } } } int q; cin >> q; for (int i = 0, x, y; i < q; i += 1) { cin >> x >> y; if (p[x] == p[y]) { cout << "No\n"; } else { bool ok = false; if (g[x].size() <= sn) { for (int z : g[x]) { if (p[z] == p[y]) { ok = true; } } } else { ok = adj[x].contains(p[y]); } if (ok) { cout << "Yes\n"; for (int z : sg[x]) { adj[z].extract(p[x]); adj[z].insert(p[y]); } p[x] = p[y]; } else { cout << "No\n"; } } } }