n = int(input())
A = [int(i) for i in input().split()]
q = int(input())
Q = []
for i in range(q):
    b, c = [int(j) for j in input().split()]
    A = [k if k != b else c for k in A]
    Q.append(sum(A))
for i in Q:
    print(i)
