N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
B = [[int(i) for i in input().split()] for Q in range(Q)]

p = [0]*100000
for i in range(N):
    p[A[i]] += 1

for i in range(Q):
    p[B[i][1]] += p[B[i][0]]
    p[B[i][0]] = 0

    cnt = 0
    for j in range(100000):
        cnt += p[j]*j
    print(cnt)
