#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    int plc = n / k;
    if (plc >= m) {
      cout << m << endl;
      continue;
    } else {
      int a = ceil((m - plc) * 1.0 / (k - 1));
      cout << (plc - max(1, a)) << endl;
    }
  }
}
