n = int(input())
A = list(map(int, input().split()))
q = int(input())

S = sum(A)
dp = [0] * 100001
for a in A:
    dp[a] += 1


for i in range(q):
    a, b = map(int, input().split())
    dp[b] += dp[a]
    S = S + (b - a) * dp[a]
    print(S)
    dp[a] = 0
