import bisect
n = int(input())
a = list(map(int,input().split()))
q = int(input())
b=[]
c=[]
sum=0
for i in range(n):
    sum+= a[i]
for i in range(q):
    bb,cc = map(int,input().split())
    b.append(bb)
    c.append(cc)
a.sort()

for i in range(q):
    l= bisect.bisect_left(a,b[i])
    h= bisect.bisect_right(a,b[i])
    for j in range(l,h):
        a[j]=c[i]
    a.sort()
    sum=sum + (c[i]-b[i])*(h-l)
    print(sum)