import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 class dsu(): n=1 parent_or_size=[-1 for i in range(n)] def __init__(self,N): self.n=N self.num = N self.parent_or_size=[-1 for i in range(N)] def merge(self,a,b): assert 0<=a0: result2.append(result[i]) return result2 def count(self): return self.num n, m = mi() P = li() AB = [li() for _ in range(m)] Q = [li() for _ in range(ii())] nowworld = [v - 1 for v in P] #n人の今いるワールド worldlist = [set() for _ in range(n)] for i in range(n): worldlist[nowworld[i]].add(i) graph = [set() for _ in range(n)] ans = [] for u, v in AB: u -= 1; v -= 1 graph[u].add(v) graph[v].add(u) def common(x, y): if len(graph[x]) < len(worldlist[nowworld[y]]): for v in graph[x]: if v in worldlist[nowworld[y]]: return True return False else: for v in worldlist[nowworld[y]]: if v in graph[x]: return True return False ans = [] import time t1 = time.time() for i in range(len(Q)): x, y = Q[i] x -= 1; y -= 1 if time.time() - t1 >= 1.7: ans = [] break if nowworld[x] != nowworld[y] and common(x, y): worldlist[nowworld[x]].discard(x) nowworld[x] = nowworld[y] worldlist[nowworld[x]].add(x) ans.append('Yes') else: ans.append('No') else: for v in ans: print(v) exit() nowworld = [v - 1 for v in P] #n人の今いるワールド worldleaderlist = [Counter() for _ in range(n)] U = dsu(n) for u, v in AB: u -= 1; v -= 1 U.merge(u, v) for i in range(n): worldleaderlist[nowworld[i]][U.leader(i)] += 1 for _ in range(len(Q)): x, y = Q[i] x -= 1; y -= 1 if nowworld[x] != nowworld[y] and worldleaderlist[nowworld[y]][U.leader(x)] > 0: ans.append('Yes') worldleaderlist[nowworld[x]][U.leader(x)] -= 1 nowworld[x] = nowworld[y] worldleaderlist[nowworld[x]][U.leader(x)] += 1 else: ans.append('No') for v in ans: print(v)