N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC= [list(map(int, input().split()))]
for i in range(1,Q):
    BC.append(list(map(int, input().split())))
    
print
for q in range(Q):
    for i in range(N):
        if A[i] == BC[q][0]:
            A[i] = BC[q][1]
    print(sum(A))
    