#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  if (n / k > m) {
    cout << m << "\n";
  } else {
    int p1 = n / k;
    m -= p1;
    int max = 0;
    while (m > 0) {
      max++;
      for (int i = 0; i < k - 1; i++) {
        m--;
      }
    }
    cout << p1 - max << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
