#include <bits/stdc++.h>
using namespace std;
void _main(int tc) {
  int n, m, k;
  cin >> n >> m >> k;
  int cardsPerPlayer = n / k;
  if (m <= cardsPerPlayer) {
    cout << m << '\n';
    return;
  }
  int remJokers = m - cardsPerPlayer;
  int maxim = remJokers / (k - 1) + (remJokers % (k - 1) != 0);
  cout << cardsPerPlayer - maxim << '\n';
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int tc;
  cin >> tc;
  for (int i = 0; ((0 < tc ? 1 : -1) < 0) ? i > tc : i < tc;
       i += (0 < tc ? 1 : -1))
    _main(i + 1);
}
