n = int(input())

nums = list(map(int, input().split()))
q = int(input())

ans = []

for _ in range(q):
    b, c = map(int, input().split())
    
    nums = sorted(nums)

    if b in nums:
        cnt = 0
        is_b = True
        while is_b:
            nums.remove(b)
            cnt += 1
            if not b in nums:
                is_b = False
                nums = nums + [c] * cnt


    ans.append(sum(nums))

for a in ans:
    print(a)