#include <bits/stdc++.h>
#define endl "\n"
#define INT long long int

using namespace std;

char infile[100], outfile[100];

int main() {
    ios::sync_with_stdio(false);
    INT T,a, b, n, t, i, I,c,d,m,k;
    cin >> T;
    for(I=1;I<=T;I++){
        sprintf(infile, ".%d.in", I);
        freopen(infile, "w", stdout);
        scanf("%lld %lld %lld",&n, &m, &k);
        printf("%lld %lld %lld\n", n, m, k);
        sprintf(outfile, ".%d.out", I);
        freopen(outfile, "w", stdout);
        a = min(m,n/k);
        b = (m - a+k-2)/(k-1);
        printf("%lld\n",a-b);
    }
}
