#include <bits/stdc++.h>
using namespace std;
long double ans, t, n, m, k, a, b, c, x, y;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> a >> b >> c;
    if (a / c >= b)
      cout << b << "\n";
    else {
      ans = floor((a / c) - (b - a / c) / (c - 1));
      cout << fixed << setprecision(0);
      cout << ans << "\n";
    }
  }
  return 0;
}
