#include using namespace std; int main() { int t; cin >> t; while (t--) { int n,m,k; cin >> n >> m >> k; k %= m; cout << ((k <= n)?0:k) << endl; } }