N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]
S = sum(A)
B_count = 0

for Q_count in range(Q):
    B_count = A.count(B[Q_count])
    S = S + (C[Q_count] - B[Q_count]) * B_count
    print(S)

    while 1:
        try:
            A_idx = A.index(B[Q_count])
        except ValueError:
            break

        A[A_idx] = C[Q_count]

