n=int(input())
l=[int(k) for k in input().split()]
lnew={}
for i in l:
  if i in lnew:
    lnew[i]+=1
  else:lnew[i]=1

k=int(input())
for i in range(k):
  a,b=input().split()
  a=int(a)
  b=int(b)
  if a in lnew:
    c=0
    if b in lnew:
      c=lnew[b]
    lnew[b]=c+lnew[a]
  lnew.pop(a,None)
  Sum=0
  for num,val in lnew.items():
    Sum+=num*val
  print(Sum)