N = int(input())

A = list(map(int,input().split()))
ok = [0]*pow(10,5)
Q = int(input())

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

for i in range(N):
    ok[A[i]]+=1
memo=0

S = sum(A)
for i in range(Q):
    print(S + ok[li[i][0]]*(li[i][1]-li[i][0]))
    a = ok[li[i][0]]
    ok[li[i][1]]+=a
    ok[li[i][0]]=0