n=int(input(""))
ain=input("").split(" ")
a={1:0,}
c=[]
for i in range(n):
    c+=[int(ain[i])]
s=sum(c)
for i in range(n):
    if (c[i] in a):
        a[c[i]]+=1
    else:
        a[c[i]]=1
q=int(input(""))
c=[]
listb=[]
listc=[]
for i in range(q):
    c=+[input("").split(" ")]
    listb+=[int(c[i][0])]
    listc+=[int(c[i][1])]
    if (listb[i] in a and a[listb[i]]!=0):
        s+=(listc[i]-listb[i])*a[listb[i]]
        if (listc[i] in a):
            a[listc[i]]+=a[listb[i]]
        else:
            a[listc[i]]=a[listb[i]]
    
    print(s)
    
    
    
