import bisect
def index(a, x):
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

n = int(input())
alist = list(map(int,input().split()))
q = int(input())

bclist = []
for i in range(q):
    b,c  = map(int,input().split())
    bclist.append([b,c])

alist = sorted(alist)

for i in range(q):
    
    b = bclist[i][0]
    c = bclist[i][1]
    try:
        ind = index(alist,b)
        while alist[ind] == b:
            alist.remove(b)
            bisect.insort(alist, c)
            if b > c:
                ind+=1

    except:
        None
    print(sum(alist))
