N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for i in range(Q):
    input_q = list(map(int, input().split()))
    B.append(input_q[0])
    C.append(input_q[1])

for i in range(Q):
    A = [C[i] if j == B[i] else j for j in A]
    print(sum(A))
