#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
long double tick() {
  static clock_t oldt;
  clock_t newt = clock();
  long double diff = 1.0L * (newt - oldt) / CLOCKS_PER_SEC;
  oldt = newt;
  return diff;
}
inline long long int sc() {
  long long int a;
  scanf("%lld", &a);
  return a;
}
inline int scd() {
  int a;
  scanf("%d", &a);
  return a;
}
inline double scf() {
  double a;
  scanf("%lf", &a);
  return a;
}
template <typename T1>
void printIt(T1 t1) {
  cout << t1 << " )" << endl;
}
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) {
  cout << t1 << " , ";
  printIt(t2...);
}
long long int powP(long long int x, long long int y) {
  long long int ans = 1, po = x % mod;
  while (y > 0) {
    if (y & 1) ans = ans * po % mod;
    y >>= 1;
    po = po * po % mod;
  }
  return ans;
}
bool bitSet(long long int n, long long int bit) {
  if ((n & (1LL << bit)) != 0)
    return true;
  else
    return false;
}
long long int findGcd(long long int a, long long int b) {
  while (a != 0) {
    long long int temp = b % a;
    b = a;
    a = temp;
  }
  return b;
}
int main() {
  int t = sc();
  while (t--) {
    long long int n = sc(), jokers = sc(), players = sc();
    long long int mx = min(n / players, jokers);
    jokers -= mx;
    long long int secondMax =
        (jokers == 0) ? 0 : (jokers - 1) / (players - 1) + 1;
    printf("%lld\n", mx - secondMax);
  }
  return 0;
}
