N = int(input())
A = list(map(str, input().split()))
Q = int(input())
BC = [list(map(str, input().split())) for i in range(Q)] 

a =""
for i in A[:N-1]:
  a += i+" " 
a += A[N-1]

for i in BC:
  B = i[0]
  C = i[1]
  if B in a:
    a = a.replace(B,C)
  print(sum(list(map(int, a.split()))))
  