#include <stdio.h>
#include <math.h>
// Define PI as specified in the problem description
#define PI 3.14159265359
int main() {
int N;
double tc, tw;
// 1. Read the number of test points
if (scanf("%d", &N) != 1) return 0;
// 2. Read the leak parameters (Center angle and Half-width)
scanf("%lf %lf", &tc, &tw);
// Loop through each point
for (int i = 0; i < N; i++) {
double x, y, vx, vy;
// Read position (x0, y0) and velocity (vx, vy)
scanf("%lf %lf %lf %lf", &x, &y, &vx, &vy);
int reflections = 0;
int escaped = 0;
// Simulate up to 10000 reflections
while (reflections < 10000) {
// --- Step 1: Find next impact point ---
// Calculate dot product of position and velocity
double dot = x * vx + y * vy;
// Distance t to the next intersection on a unit circle
// Derived from |P + tV|^2 = 1 => t = -2(P.V)
double t = -2 * dot;
// Update position to the new impact point
x = x + vx * t;
y = y + vy * t;
// --- Step 2: Check if we hit the leak ---
// Calculate angle of current position in radians (-PI to PI)
double angle = atan2(y, x);
// Calculate the shortest angular distance to the leak center
double diff = fabs(angle - tc);
// Handle angular wrapping (e.g. distance between 359° and 1°)
if (diff > PI) {
diff = 2 * PI - diff;
}
// If inside the leak width, we escape
if (diff <= tw) {
escaped = 1;
// Output the number of reflections *before* this escape
printf("%d\n", reflections);
break;
}
// --- Step 3: Reflect Velocity ---
// If we didn't escape, we bounce.
// Reflection formula: V_new = V_old - 2*(V_old . Normal) * Normal
// For a unit circle, the Normal vector is the position vector (x, y)
double v_dot_n = vx * x + vy * y;
vx = vx - 2 * v_dot_n * x;
vy = vy - 2 * v_dot_n * y;
// Increment reflection count
reflections++;
}
// If we reached 10000 bounces without escaping
if (!escaped) {
printf("10000\n");
}
}
return 0;
}