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