import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

import bisect

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