n=int(input())
a=list(map(int, input().split()))
q=int(input())
bc=[]

for i in range (q):
    bc.append(list(map(int, input().split())))
num=[0]*(10**5+1)
for i in range(n):
    x=a[i]
    num[x]+=1


for k in range (q):
    b=bc[k][0]
    c=bc[k][1]
    num[c]+=num[b]
    num[b]=0
    kk=0
    for l in range(10**5+1):
        kk+=l*num[l]
    print(kk)