N=int(input())
A=list(map(int,input().split()))
Q=int(input())
s=0 
for k in range(len(A)):
  s=s+A[k]
  
for i in range(Q):
  B,C=map(int,input().split())
  m=0
  for j in range(len(A)):
    if A[j]==B:
      A[j]=C
      m+=1
  s=s+m*(C-B)
  print(s)
