import sys
import math

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
S = list(list(map(int, input().split())) for _ in range(Q))

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