import collections
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]

ans = sum(A)
cnt = collections.Counter(A)

dp = [0]*(10**5+1)

for i in cnt.items():
    dp[i[0]] = i[1]

for i in range(Q):
    ans += (BC[i][1] - BC[i][0]) * dp[BC[i][0]]
    dp[BC[i][1]] += dp[BC[i][0]]
    dp[BC[i][0]] == 0
    print(ans)
