n = int(input())
a = list(map(int, input().split()))
q = int(input())
b_c = [list(map(int,input().split())) for i in range(q)]

for i in range(q):
  b = b_c[i][0]
  c = b_c[i][1]
  b_count = a.count(b)
  a = [i for i in a if i != b]
  for i in range(b_count):
    a.append(c)
  print(sum(a))