n = int(input())
a = list(map(int, input().split()))
q = int(input())
for j in range(q):
  bc = list(map(int, input().split()))
  res = bc[0]
  for j in range(n):
    if a[j] == res:
      a[j] = bc[1]
    else:
      a[j] = a[j]
  print(sum(a))