import numpy as np
n=int(input())
a=list(map(int,input().split()))
q=int(input())
table = [[int(i) for i in input().split()] for q in range(q)]

b=np.array(table)

for i in range(q):
 a = [b[i,1] if k == b[i,0] else k for k in a]
 print(sum(a))

