N, M = list(map(int, input().split())) P = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] Q = int(input()) XY = [list(map(int, input().split())) for _ in range(Q)] P = [P[i] - 1 for i in range(N)] FriendCnt = [0] * N FriendData = [[] for _ in range(N)] for a, b in AB: a -= 1 b -= 1 FriendCnt[a] += 1 FriendCnt[b] += 1 FriendData[a].append(b) FriendData[b].append(a) Boader = 2000 TypeList = [0] * N NotifyList = [] FreField = {} for i in range(N): if FriendCnt[i] > Boader: NotifyList.append(i) TypeList[i] = 1 FreField[i] = [0] * N for j in FriendData[i]: FreField[i][P[j]] += 1 FreNoticeList = [[] for _ in range(N)] for i in range(N): for d in FriendData[i]: if TypeList[d]: FreNoticeList[i].append(d) Eto = [P[i] for i in range(N)] def nasu(x, y): xroom = Eto[x] yroom = Eto[y] if xroom == yroom: return False if TypeList[x]: return FreField[x][yroom] != 0 else: for d in FriendData[x]: droom = Eto[d] if droom == yroom: return True return False for x, y in XY: x -= 1 y -= 1 if nasu(x, y): print("Yes") xroom = Eto[x] yroom = Eto[y] for d in FreNoticeList[x]: FreField[d][xroom] -= 1 FreField[d][yroom] += 1 Eto[x] = yroom else: print("No")