#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	int T;
	cin >> T;
	while(T--) {
		int N, M, X;
		cin >> N >> M >> X;
		if(X == M || X == 0) {
			cout << "0\n";
			continue;
		}
		int ans = 0;
		while(N > X) {
			ans += X;
			N -= X+1;
		}
		if(N > 0) ans += N-1;
		cout << ans << "\n";
	}
}