#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, k;       cin >> n >> m >> k;       int cardsPlayer = n / k;       double maxCard;       int jokerMax = min(m, cardsPlayer);       maxCard = ceil((m - jokerMax) / (k - 1.0));       if (jokerMax - maxCard > 0)         cout << jokerMax - maxCard << endl;       else         cout << 0 << endl;     }     return 0;   }   