from collections import deque
n=int(input())
a=list(map(int,input().split()))

sus=deque([sum(a)])
q=int(input())
for i in range(q):
  count=0
  b,c=map(int,input().split())
  for j in range(n):
    if a[j]==b:
      a[j]=c
      count+=1
  sus.append(sus[-1]+(c-b)*count)
  print(sus[-1])
#print(sus)