#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, n, m, k, p, q, r, i, j, d, f = 0;
  cin >> t;
  while (t--) {
    cin >> n >> m >> k;
    p = n / k;
    q = min(p, m);
    r = m - q;
    cout << q - ceil((double)r / (k - 1)) << endl;
  }
}
