N = int(input())
A = [int(x) for x in input().split()]
Q = int(input())
ans = []
for x in range(Q):
    B, C = [int(x) for x in input().split()]
    A = [x if x != B else C for x in A]
    ans.append(sum(A))
print(ans)