from bisect import bisect_left
N = int(input())
a=list(map(int, input().split()))
Q = int(input())
b=[]
c=[]
def index(lst, e):
    # Step 1. bisect_left して
    i = bisect_left(lst, e)
    
    # Step 2. 変な値を ValueError で弾いて
    if i == len(lst):
        raise ValueError
    if lst[i] != e:
        raise ValueError
    
    # Step 3. 値を返す。
    return i
for i in range(Q):
  b1,c1=map(int, input().split())
  b.append(b1)
  c.append(c1)

a.sort()
for i in range(Q):
  first=0
  last = 0
  a.sort()
  if b[i] not in a:
    print(sum(a))
  else:
    last = a.count(b[i])
    first = index(a,b[i])
    del a[first:first+last]
    list_c = [c[i]]*last
    a = a+list_c
    print(sum(a))