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:
        nums = [(c if num == b else num) for num in nums]
    
    ans.append(sum(nums))

for a in ans:
    print(a)