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

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

