(dotimes [q (read)] (let* [[n (read)][m (read)][k (read)]] (let [[x (mod k m)]] (if (<= x (- m n)) (print 0) (print x)))))