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

anum=[]
asum=sum(a) #当初の数列Aの要素の和

for i in a:
  acnt=a.count(i)
  anum.append([i,acnt])

d=dict(anum) #当初の数列Aの各整数の数のdictionary

for i in range(q):
  if bc[i][0] not in d.keys():
    print(asum)
  if bc[i][0] in d.keys():
    x=(bc[i][1]-bc[i][0])*d[bc[i][0]]
    print(asum+x)
    asum+=x
    if bc[i][1] in d.keys():
      d[bc[i][1]]=d[bc[i][1]]+d[bc[i][0]]
      d[bc[i][0]]=0
    else:
      d[bc[i][1]]=d[bc[i][0]]
      d[bc[i][0]]=0