import bisect
import sys
input = sys.stdin.readline


N = int(input())
alist = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]


alist.sort()
sumA = sum(alist)
for b, c in BC:
    idx_bl = bisect.bisect_left(alist, b)
    idx_br = bisect.bisect_right(alist, b)

    alist = alist[:idx_bl] + alist[idx_br:]
    idx_cl = bisect.bisect_left(alist, c)
    alist = alist[:idx_cl] + [c] * (idx_br - idx_bl) + alist[idx_cl:]

    sumA -= (idx_br - idx_bl) * (b - c)
    print(sumA)
