#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
string str, s;
vector<int> arr;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int c, j, p;
    cin >> c >> j >> p;
    int x = c / p;
    if (x >= j) {
      cout << j << endl;
    } else {
      int f = x;
      j = j - x;
      int se = (j / (p - 1));
      if ((j % (p - 1)) != 0) se++;
      cout << f - se << endl;
    }
  }
}
