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

a = [0] * (10 ** 5 + 1)
ans = sum(A)

for i in range(N):
    a[A[i]] += 1

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