n = int(input())
a = list(map(int,input().split()))
q = int(input())
ans = sum(a)
many =[0]*(10**5)
bc = [0]*q
for i in range(10**5) :
    many[i] = a.count(i+1)

for i in range(q) :
    bc[i] = list(map(int,input().split()))

for i in range(q) : 
    ans += (bc[i][1] - bc[i][0]) * many[bc[i][0] - 1]
    print(ans)
    many[bc[i][1]-1] += many[bc[i][0]-1]
    many[bc[i][0]-1] =0

