N = int(input())
A = sorted(map(int, input().split()))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

ans = sum(A)
nums = [A.count(num) for num in range(10 ** 5)]

for i in range(Q):
    ans += (C[i] - B[i]) * nums[B[i]]
    nums[C[i]] += nums[B[i]]
    nums[B[i]] = 0
    print(ans)