#include <bits/stdc++.h>
using namespace std;
void sol() {
  int n;
  int m, k;
  cin >> n;
  cin >> m >> k;
  int points = 0;
  int cards = n / k;
  if (m <= cards) {
    points = m;
  } else {
    int winner = cards;
    m = m - cards;
    k = k - 1;
    if (m % k == 0) {
      m = m / k;
    } else {
      m = m / k + 1;
    }
    points = winner - m;
  }
  cout << points << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t-- > 0) {
    sol();
  }
  return 0;
}
