#include <bits/stdc++.h>
using namespace std;
const long long LLINF = 1e18;
const int INF = 1e9;
const int MOD = 20101009;
const int HMOD = 999959;
const int VMOD = 5000000;
const int MAXN = 3e5 + 10;
const int MAXM = 5e5 + 10;
const int INV = 10050505;
const long long LLINV = 1e18;
const double eps = 1e-3;
int dirx[5] = {0, -1, 1, 0, 0}, diry[5] = {0, 0, 0, -1, 1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int x = n / k;
    if (m <= x)
      printf("%d\n", m);
    else
      printf("%d\n", x - (m - x + k - 2) / (k - 1));
  }
  return 0;
}
