n = int(input())
line_a = list(map(int,input().split()))
total = sum(line_a)
q = int(input())
for i in range(q):
  b,c = map(int, input().split())
  for j in range(len(line_a)):
    if line_a[j] == b:
      line_a[j] = c
  print(sum(line_a))