#include <bits/stdc++.h>
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
struct debug {
  template <class T>
  debug& operator<<(const T&) {
    return *this;
  }
};
using ll = long long;
template <typename T>
void min_self(T& a, T b) {
  a = min(a, b);
}
template <typename T>
void max_self(T& a, T b) {
  a = max(a, b);
}
int divide(int a, int b) { return (a + b - 1) / b; }
void test_case() {
  int n, m, k;
  cin >> n >> m >> k;
  if (m <= n / k) {
    cout << m << '\n';
  } else {
    int ans = n / k;
    m -= n / k;
    ans -= divide(m, k - 1);
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    test_case();
  }
}
