#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    int card = n / k;
    int joker;
    if (card >= m)
      cout << m << endl;
    else {
      m -= card;
      int left = ceil(double(m) / double(k - 1));
      cout << card - left << endl;
    }
  }
  return 0;
}
