#入力
N = int(input())
Alist = list(map(int,input().split()))
Alist.sort()
Q = int(input())
Blist = []
Clist = []
for i in range(Q):
  B, C = map(int,input().split())
  Blist.append(B)
  Clist.append(C)

for j in range(Q):
  num = Alist.count(Blist[j])
  if num == 0:
    break
  else:
    firstindex = Alist.index(Blist[j])
    for l in range(num):
      Alist[firstindex+l] = Clist[j]
  print(sum(Alist))
  Alist.sort()