#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
long long power(long long a, long long b, long long m = MOD) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return ans;
}
long long dir[] = {-1, 0, 1, 0, -1};
long long dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
long long dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long N = 1e5 + 1;
void solve() {
  long long n, m, k;
  cin >> n >> m >> k;
  long long win = n / k;
  if (win >= m)
    cout << m << "\n";
  else
    cout << win - ceil(((double)(m - win)) / ((double)(k - 1))) << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  cin >> t;
  while (t--) solve();
}
