
if __name__=='__main__':
    N = int(input())
    A = input().split(" ")
    A = [int(s) for s in A]
    Q=int(input())
    str_list=[]
    S=[]
    sum=0
    count=[0]*100000
    for i in range(len(A)):
         count[A[i]]=count[A[i]]+1

    for i in range(len(count)):
         sum=sum+i*count[i]

    for i in range(Q):
        str_list.append(list(input().split()))

    for j in range(Q):
        motonum=int(str_list[j][0])
        chnum=int(str_list[j][1])
        #print(motonum)
        #print(chnum)
        if count[motonum]!=0:
            sum=sum+(chnum-motonum)*count[motonum]
            count[chnum]=count[motonum]+count[chnum]
            count[motonum] = 0

        print(sum)
