n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

for i in bc:
    str_a = " ".join(map(str, a))
    str_a = str_a.replace(str(i[0]), str(i[1]))
    a = list(map(int, str_a.split()))
    print(sum(a))