N = int(input())
A = list(map(int, input().split()))
Q = int(input())
#print(Q)
list = []

for i in range(Q):
    a,b=input().split()
    list.append((int(a), int(b)))
#print(list[1][1])
for i in range(Q):
  for j in range(N):
      if  A[j] == list[i][0]:
        A[j] = list[i][1]
  print(sum(A))