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