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

Q = int(input())
BC= [input().split() for _ in range(Q)]

for j in range(Q):
    A = [int(BC[j][1]) if i == int(BC[j][0]) else i for i in A]
    print(sum(A))