import sys
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = []
for q in range(Q):
    bc = list(map(int, input().split()))
    BC.append(bc)


for bc in BC:
    ind = [i for i, x in enumerate(A) if x==bc[0]]
    for i in ind:
        A[i] = bc[1]
    print(sum(A))