#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    int per_person = n / k;
    if (m <= per_person)
      cout << m << endl;
    else {
      int baki = m - per_person;
      double sobai_pabe = ceil(baki * 1.0 / (k - 1));
      cout << per_person - sobai_pabe << endl;
    }
  }
}
