N = int(input())
A = list(map(int, input().split()))
Q = int(input())
bc = []
for _ in range(Q):
    bc.append(list(map(int, input().split())))

for i in range(Q):
    b = bc[i][0]
    c = bc[i][1]
    A = [c if i == b else i for i in A]
    print(sum(A))