a=int(input())
l=list(map(int,input().split()))
b=int(input())
initial_sum=sum(l)
for _ in range(b):
  l1=list(map(int,input().split()))
  x=l1[0]
  y=l1[1]
  z=l.count(l1[0])
  for i in range(len(l)):
    if l[i] ==l1[0]:
      l[i]=l1[1]
  initial_sum+=(y-x)*z
  print(initial_sum)