#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, m, y, x, t, l, k, r, a, b, c, d, p = 1, q, i, j, ans = 0,
                                                    ans1 = 0;
  string s1, s2, s3, s = "1";
  char ch;
  cin >> t;
  while (t--) {
    cin >> n >> m >> k;
    ans = 0;
    x = min(n / k, m);
    m -= x;
    k--;
    y = (long long int)ceil((double)m / k);
    cout << x - y << "\n";
  }
  return 0;
}
