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)
    A = [C[Q_count] if A[i] == B[Q_count] else A[i] for i in range(N)]

