n = int(input())
a_list = list(map(int, input().split()))
a_sum = sum(a_list)
q = int(input())
b = []
c = []
for i in range(q):
  bi, ci = map(int, input().split())
  b.append(bi)
  c.append(ci)

b_num = []
for i in range(q):
  num = 0
  for j in range(len(a_list)):
    if a_list[j] == b:
      num += 1
  b_num.append(num)

for i in range(q):
  if b[i] <= c[i]:
    a_sum += (c[i] - b[i]) * b_num[i]
  else:
    a_sum -= (b[i] - c[i]) * b_num[i]
  print(a_sum)