#include <bits/stdc++.h>
using namespace std;
int char_to_int(char c) {
  int x = c - 48;
  return x;
}
char int_to_char(int x) {
  int c = x + 48;
  return c;
}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
map<int, int> mp;
vector<int> v;
map<int, vector<int> > G;
map<int, int> visited;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  fast();
  int tst;
  cin >> tst;
  while (tst--) {
    int n, m, k;
    cin >> n >> m >> k;
    int x = n / k;
    int p = min(x, m);
    k--;
    int q = max(0, m - p);
    int a = (q / k);
    if (q % k) a++;
    cout << p - a << endl;
  }
  return 0;
}
