N = int(input())
A = input().split()
A = [int(x) for x in A]
Q = int(input())
BC = []
for i in range(Q):
    bc = input().split()
    bc = [int(x) for x in bc]
    BC.append(bc)


for j in range(Q):
    for k in range(N):
        if A[k] == BC[j][0]:
            A[k] = BC[j][1]
    total = sum(A)
    print(total)
    