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 p = list(map(int, input[ptr:ptr+n])) ptr += n current_world = [0] * (n + 1) # 1-based indexing for i in range(n): current_world[i+1] = p[i] inhabitants = defaultdict(set) for i in range(1, n+1): inhabitants[current_world[i]].add(i) friends = [set() for _ in range(n+1)] for _ in range(m): a = int(input[ptr]) b = int(input[ptr+1]) ptr += 2 friends[a].add(b) friends[b].add(a) q = int(input[ptr]) ptr += 1 for _ in range(q): x = int(input[ptr]) y = int(input[ptr+1]) ptr += 2 x_w = current_world[x] y_w = current_world[y] if x_w == y_w: print("No") continue # Check if friends[x] and inhabitants[y_w] have any common element if not friends[x].isdisjoint(inhabitants[y_w]): print("Yes") # Move x from x_w to y_w inhabitants[x_w].remove(x) inhabitants[y_w].add(x) current_world[x] = y_w else: print("No") if __name__ == "__main__": main()