N=int(input())
array = list(map(int,input().strip().split()))
Q = int(input())
ka=[]
for i in range(Q):
  moment = list(map(int,input().strip().split()))
  ka.append(moment)
  
for j in range(Q):
  if j==0:
    for i in range(N):
     if array[i]==ka[j][0]:
      array[i]=ka[j][1]
    sama = sum(array)
    print(sama)
  else:
    for i in range(N):
      if array[i]==ka[j][0]:
        array[i]=ka[j][1]
        sama = sama+(ka[j][1]-ka[j][0])
    print(sama)
      