n = int(input())
 
a = list(map(int, input().split()))
q = int(input())
s = []
S = sum(a)

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