use std::io; fn main() { let mut n = String::new(); io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); for _ in 0..n { let mut s = String::new(); io::stdin().read_line(&mut s); let mut itr = s.trim().split_whitespace(); let mut n: usize = itr.next().unwrap().parse().unwrap(); let mut m: usize = itr.next().unwrap().parse().unwrap(); let mut k: usize = itr.next().unwrap().parse().unwrap(); let a = k % m; println!("{}", if a < m - n { a } else { 0 } ); } }