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