import collections
n = int(input())
li = list(map(int,input().split()))
q = int(input())
num_li=[list(map(int,input().split())) for i in range(q)]

li.sort()
for i,j in num_li:
    if i in li:
        cnt = li.count(i)
        li = [k for k in li if k != i] + [j]*cnt
    print(sum(li))