#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, i, t, j, cp, max1, max2, p1, ramas, alt;
  cin >> t;
  for (i = 1; i <= t; i++) {
    cin >> n >> m >> k;
    cp = n / k;
    if (cp >= m)
      cout << m << '\n';
    else {
      p1 = cp;
      ramas = m - p1;
      alt = ramas / (k - 1);
      if (ramas % (k - 1) != 0) alt++;
      cout << p1 - alt << '\n';
    }
  }
  return 0;
}
