#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int a = 0; a < t; a++) {
    int n, m, k;
    cin >> n >> m >> k;
    if (n / k >= m) {
      cout << m << "\n";
    } else {
      cout << n / k - ((m - n / k - 1) / (k - 1) + 1) << "\n";
    }
  }
}
