N = int(input())

target_list = map(int, input().split())
result = []

for i in range(int(input())):
    B, C = map(int, input().split())
    target_list = [C if i == B else i for i in target_list]
    result.append(sum(target_list))

for i in result:
    print(i)
