N = int(input())
A = list(map(int, input().split()))
newA = sorted(A)
Q = int(input())

for i in range(Q):
    B, C = map(int, input().split())
    newA = [C if i == B else i for i in newA]
    print(sum(newA))