#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, k, c = 0;
    cin >> n >> m >> k;
    int a = n / k;
    if (a >= m) {
      cout << m << endl;
    } else {
      int b = m - a;
      int c = b / (k - 1);
      if (b % (k - 1) != 0) c++;
      cout << a - c << endl;
    }
  }
  return 0;
}
