n = int(input())
a = sorted(list(map(int,input().split())))
ans = sum(a)
#print(ans)
q = int(input())
b = []
c = []
for i in range(q):
    bb,cc = map(int,input().split())
    b.append(bb)
    c.append(cc)
#print(b)
#print(c)
from itertools import groupby
d = [[key,len(list(group))] for key,group in groupby(sorted(a))]
#print(d)
for j in range(q):
    for i in range(len(d)):
        if b[j]==d[i][0]:
            d[i][0] = c[j]
            ans = ans + ((c[j]-b[j])*d[i][1])
    print(ans)