import bisect
def ints(): return map(int, input().split())
def _int(): return int(input())


_ = _int()
arr = sorted(ints())
n = _int()
changes = []
for _ in range(n):
    target, desired = ints()
    changes.append((target, desired))

for target, desired in changes:
    idx = bisect.bisect_left(arr, target)
    for i, v in enumerate(arr[idx::], idx):
        if v != target:
            break
        arr[i] = desired
    arr = sorted(arr)
    print(sum(arr))
