N = int(input())
A = list(map(int, input().split()))
Q = int(input())

BC = []
for i in range(Q):
    BC.append(list(map(int, input().split())))

for i in range(Q):
    B = [BC[i][1] if l == BC[i][0] else l for l in A]
    print(sum(B))
    A = B