//#include #include #include #include #include #include //#include //using namespace __gnu_pbds; using namespace std; #ifdef LOCAL #define show(x) cerr << #x" = " << (x) << "\n" #else #define show(x) 0 #endif #define pb push_back #define pp pop_back #define mp make_pair #define fst first #define snd second #define FOR(var, from, to) for(int var = from; var < int(to); ++var) #define all(x) x.begin(), x.end() #define rev(x) x.rbegin(), x.rend() #define sz(x) int(x.size()) #define vec(x) vector #define INF 2000000000 typedef long long ll; typedef pair pii; typedef pair pll; //typedef tree,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // use unique second element of pair to work as multiset //typedef tree,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset; const ll mod = 1000000007, mod2 = 998244353; template ostream &operator<<(ostream &os, pair p){os << "(" << p.fst << "," << p.snd << ")"; return os;} template istream &operator>>(istream &is, pair &p){is >> p.fst >> p.snd; return is;} template istream &operator>>(istream &is, vector &v){FOR(i, 0, v.size()) is >> v[i]; return is;} template ostream &operator<<(ostream &os, vector v){for(T x : v) os << x << " "; return os;} template ostream &operator<<(ostream &os, set s){for(T x : s) os << x << " "; return os;} template ostream &operator<<(ostream &os, multiset s){for(T x : s) os << x << " "; return os;} template ostream &operator<<(ostream &os, map m){for(auto x : m) os << x << " "; return os;} //ostream &operator<<(ostream &os, ordered_set s){for(int x : s) os << x << " "; return os;} //ostream &operator<<(ostream &os, ordered_multiset s){for(pii x : s) os << x.fst << " "; return os;} ll mod_pow(ll a, ll b, ll m){ ll sol = 1; while(b){ if(b&1){ sol = (sol*a)%m; b--; }else{ a = (a*a)%m; b/=2; } } return sol;} ll rem(ll a, ll b){ ll res = a%b; return res < 0 ? res+b : res; } void test_case(){ int n, m, k; cin >> n >> m >> k; int r = k % m; if(r < m - n){ cout << r << "\n"; }else{ cout << "0\n"; } } int main(){ #ifndef LOCAL ios_base::sync_with_stdio(false); cin.tie(NULL); #endif int t; cin >> t; FOR(i, 0, t) test_case(); return 0; }