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

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