import sys from collections import defaultdict def main(): input = sys.stdin.read().split() ptr = 0 N, M = int(input[ptr]), int(input[ptr+1]) ptr += 2 current_world = [0] * (N + 1) # 1-based for i in range(1, N+1): current_world[i] = int(input[ptr]) ptr += 1 friends = [[] for _ in range(N+1)] for _ in range(M): A = int(input[ptr]) B = int(input[ptr+1]) ptr += 2 friends[A].append(B) friends[B].append(A) # Initialize friends_in_world friends_in_world = [defaultdict(int) for _ in range(N+1)] for X in range(1, N+1): for F in friends[X]: w = current_world[F] friends_in_world[X][w] += 1 Q = int(input[ptr]) ptr += 1 for _ in range(Q): X = int(input[ptr]) Y = int(input[ptr+1]) ptr += 2 if current_world[X] == current_world[Y]: print("No") continue target_world = current_world[Y] cnt = friends_in_world[X].get(target_world, 0) if cnt >= 1: print("Yes") old_world = current_world[X] current_world[X] = target_world for F in friends[X]: # Update F's friends_in_world for old_world if friends_in_world[F][old_world] == 1: del friends_in_world[F][old_world] else: friends_in_world[F][old_world] -= 1 # Update F's friends_in_world for new_world (target_world) friends_in_world[F][target_world] += 1 else: print("No") if __name__ == "__main__": main()