import numpy as np
from numba import njit

n=int(input())
a=np.array(list(map(int, input().split())))
q=int(input())
a_sum= np.sum(a)


@njit
def func(a,b,c,a_sum):
  count=np.count_nonzero(a==b)
  a[a==b]=c
  a_sum += count*(c-b)
  return a,a_sum
  
for i in range(q):
  b,c=map(int, input().split())
  a,a_sum=func(a,b,c,a_sum)
  print(a_sum)