#include using std::cin; using std::cout; typedef long long ll; typedef long double ld; int A, B, d; void work() { int ans = 0; cin >> A >> B >> d; if (d <= B) { // fputs("Case 1:\n", stderr); int side = A / d + 1, rem = A % d; ld pos = sqrtl((ll)d * d - (ll)rem * rem); int posi = floorl(B - 2 * pos + 1e-12); ans = 2 * side; if (posi > 0) ans += posi / d + 1; } else if (3ll * d * d <= 4ll * B * B) { // fputs("Case 2:\n", stderr); ld offset = sqrtl((ll)d * d - (ll)B * B); int Ls = floorl(A / d + 1e-12), Rs = floorl((A - offset) / d + 1e-12); ld Lp = A - Ls * d, Rp = A - offset - Rs * d; ld lm = Lp <= d ? sqrtl((ll)d * d - Lp * Lp) : 0, rm = Rp <= d ? sqrtl((ll)d * d - Rp * Rp) : 0; bool more = lm + rm <= B; ans = Ls + 1; if (Rs >= 0) ans += Rs + 1 + more; } else { // fputs("Case 3:\n", stderr); ld offset = sqrtl((ll)d * d - (ll)B * B), step = 2 * offset; int Ls = floorl(A / step + 1e-12), Rs = floorl((A - offset) / step + 1e-12); ld Lp = A - Ls * step, Rp = A - offset - Rs * step; ld lm = Lp <= d ? sqrtl((ll)d * d - Lp * Lp) : 0, rm = Rp <= d ? sqrtl((ll)d * d - Rp * Rp) : 0; bool more = lm + rm <= B; ans = Ls + 1; if (Rs >= 0) ans += Rs + 1 + more; } cout << ans << '\n'; } int main() { int T; std::ios::sync_with_stdio(false), cin.tie(NULL); for (cin >> T; T; --T) work(); return 0; }