#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, m, k;
    cin >> n >> m >> k;
    int Win = min(m, n / k);
    m -= Win;
    int Lose = (m + k - 2) / (k - 1);
    cout << Win - Lose << endl;
  }
}
