#include #include using namespace std; using namespace atcoder; using ll = long long; int T, N, M, K, A; int main() { cin >> T; while (T--) { cin >> N >> M >> K; A = K % M; cout << (A < M - N ? A: 0) << endl; } return 0; }