#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    int a1 = n / k;
    int p = min(m, a1);
    int r = (m - p + k - 2) / (k - 1);
    cout << p - r << "\n";
  }
}
