N=int(input())
listA=list(map(int, input().split()))
Q=int(input())

listB=[] #appendのために宣言が必要
while True:
    try:
        listB.append(list(map(int,input().split())))

    except:
        break;
        
sum=sum(listA)
numlist=[0]*(10*5+1)
for i in range(10*5+1):
  numlist[i]=listA.count(i)
  
for i in range(Q):
  B=listB[i][0]
  C=listB[i][1]
  sum=sum+(C-B)*numlist[B]
  numlist[C]+=numlist[B]
  numlist[B]=0
  # print(numlist)
  print(sum)
