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 = 0

for Q_count in range(Q):
    if B[Q_count] in A:

        for N_count in range(N):
            if A[N_count] == B[Q_count]:
                A[N_count] = C[Q_count]
            S = S + A[N_count]

    else:
        S = sum(A)

    print(S)
    S = 0

