input()
a = list(map(int, input().split()))
b = int(input())
for i in range(b):
  c = list(map(int, input().split()))
  a = [c[1] if d == c[0] else d for d in a]
  f = 0
  for e in a:
    f += e
  print(f)