N = int(input())
A = list(map(int,input().split()))
Q = int(input())
lst = []
for _ in range(Q):
    a,b = map(int,input().split())
    lst.append([a,b])
#print(A)
#print(lst)

#rep_lst = [s.replace('1','2') for s in A]

#print(rep_lst)

for i in range(Q):
    A = [lst[i][1] if j == lst[i][0] else j for j in A]
    print(sum(A))

