import bisect
n = int(input())
a = list(map(int,input().split()))
q = int(input())
b=[]
c=[]
aa=[]
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])
    ll=bisect.bisect_left(a,c[i])
    hh= bisect.bisect_right(a,c[i])
    if b[i]>c[i]:
        a[ll+h-l:h],a[ll:ll+h-l] = a[ll:l],[c[i]]*(h-l)
    else:
        a[l+hh-h:hh],a[l:l+hh-h] = [c[i]]*(h-l),a[h:hh]
    sum=sum + (c[i]-b[i])*(h-l)
    print(sum)