def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
      
      
n = int(input())
a = [int(i) for i in input().split(' ')]
q = int(input())
b = []
c = []
for _ in range(q):
  temp = input().split(' ')
  i = int(temp[0])
  j = int(temp[1])
  k = my_index(a, i)
  while True:
    if k is False:
      break
    a[k] = j
    k = my_index(a, i)
  print(sum(a))


    