n = int(input())
list_a = list(map(int, input().split()))
q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    list_a = [c if i == b else i for i in list_a]
    print(sum(list_a))
