N = int(input())
num_list = list(map(int,input().split()))
q = int(input())

for i in range(len(num_list)):
  ans += num_list[i]

for j in range(q):
  query = list(map(int,input().split()))
  cnt = num_list.count(query)
  ans += (query[1] - query[0]) * cnt
  print(ans)