N = int(input())
l = list(map(int,input().split()))
Q = int(input())

l.sort()
m = []
count = [0 for i in range(Q)]
flag = [0 for i in range(Q)]

for i in range(Q):
    m.append(list(map(int,input().split())))

ans = sum(l)

for i in range(Q):
    for j in range(N):
        if l[j] == m[i][0]:
            count[i] += 1
        elif l[j] > m[i][0]:
            break
    for j in range(i-1,-1,-1):
        if m[j][1] == m[i][0]:
            if flag[j] == 0:
                count[i] += count[j]
                flag[j] = 1
    ans += (m[i][1]-m[i][0])*count[i]
    print(ans)
