def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N, M = int(data[idx]), int(data[idx+1]) idx +=2 pos = list(map(int, data[idx:idx+N])) idx +=N pos = [0] + pos # 1-based index current_bitmask = [0] * (N + 1) # worlds are 1-based for i in range(1, N+1): w = pos[i] current_bitmask[w] |= 1 << (i-1) friend_bitmask = [0] * (N + 1) for _ in range(M): A = int(data[idx]) B = int(data[idx+1]) idx +=2 friend_bitmask[A] |= 1 << (B-1) friend_bitmask[B] |= 1 << (A-1) Q = int(data[idx]) idx +=1 output = [] for _ in range(Q): X = int(data[idx]) Y = int(data[idx+1]) idx +=2 if pos[X] == pos[Y]: output.append("No") continue target_w = pos[Y] if (friend_bitmask[X] & current_bitmask[target_w]) != 0: output.append("Yes") old_w = pos[X] # Update current_bitmask current_bitmask[old_w] &= ~ (1 << (X-1)) current_bitmask[target_w] |= (1 << (X-1)) pos[X] = target_w else: output.append("No") print('\n'.join(output)) if __name__ == "__main__": main()