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

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