#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    int card_to_person = n / k;
    if (card_to_person >= m) {
      cout << m << "\n";
      continue;
    }
    int tmp = (m - card_to_person) / (k - 1);
    if ((m - card_to_person) % (k - 1) != 0) {
      tmp++;
    }
    cout << card_to_person - tmp << "\n";
  }
  return 0;
}
