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(' ')
#  b.append(int(temp[0]))
#  c.append(int(temp[1]))

for _ in range(q):
  temp = input().split(' ')
  i = int(temp[0])
  j = int(temp[1])
  if i in a:
    while True:
      k = my_index(a, i)
      if k is False:
        break
      a[k] = j
  print(sum(a))