import java.util.*; import java.io.*; public class Main { public static Scanner sc = new Scanner(System.in); public static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) { int t = sc.nextInt(); while( t > 0 ) { solve(); t--; } pw.flush(); } static void solve() { int N = sc.nextInt(); int M = sc.nextInt(); int K = sc.nextInt(); pw.println( K%M < M-N ? K%M : 0 ); } }