import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
from decimal import Decimal
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()
Q = I()
BC = [LI() for _ in range(Q)]
#print(N,A,Q,BC)
for i in range(Q):
    b,c = BC[i]
    #print(b,c,A)
    for i,a in enumerate(A):
        if a > b:
            break
        elif a == b:
            A[i] = c

    #A = [c if a == b else a for a in A]
    #print(A)
    A.sort()
    print(sum(A))