n=int(input())
A=list(map(int,input().split()))
Q=int(input())
Z=[]
B=[0]*Q
C=[0]*Q
for i in range(Q):
  Z.append(list(map(int,input().split())))
for i in range(Q):
  B[i]=Z[i][0]
  C[i]=Z[i][1]
#for j in range(1,Q+1):
for b in range(Q):
  for k,l in enumerate(A):
    if l==B[b]:
      A[k]=C[b]
  print(sum(A))
#print(C)
