n = int(input())
a = list(map(int, input().split()))
q = int(input())

for _ in range(q):
  b,c = map(int, input().split())
  if b in a:
    for i in range(n):
      if a[i] == b: a[i] = c
    print(sum(a))
  else:
    print(sum(a))