N = int(input())
A = list(map(int, input().split()))
Q = int(input())
answer = []
for i in range(Q):
    B, C = map(int, input().split())
    A = [C if j == B else j for j in A]
    answer.append(sum(A))
for res in answer:
    print(res)
