#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int n, m, k;
  while (t--) {
    cin >> n >> m >> k;
    int c = n / k;
    int j1 = min(m, c);
    m -= j1;
    k--;
    int j2 = ceil(m * 1.0 / k);
    cout << j1 - j2 << endl;
  }
  return 0;
}
