n = int(input())
a = list(map(int,input().split()))
q = int(input())

bc = [list(map(int,input().split())) for i in range(q)]

import bisect

a.sort()

su = sum(a)

for i in range(q):
    idx_l = bisect.bisect_left(a,bc[i][0])
    idx_r = bisect.bisect_right(a,bc[i][0])
    
    if idx_l == n:
        print(su)
        continue
    k = (idx_r-idx_l)
    diff = bc[i][1] - bc[i][0]
    a[idx_l:idx_r] = [ bc[i][1] for _ in range(k)]
    a.sort()
    su = su + (diff*k)
    print(su)