N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [None] * Q
C = [None] * Q
for i in range(Q):
    B[i], C[i] = list(map(int, input().split()))


def change(b, c):
    if b in A:
        for i in range(N):
            if A[i] == b:
                A[i] = c
    ans = sum(A)
    print(ans)

for i in range(Q):
    change(B[i], C[i])
