CF2120B.Square Pool

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Square Pool

Aryan and Harshith are playing pool in universe AX120 on a fixed square pool table of side ss with pockets at its 44 corners. The corners are situated at (0,0)(0,0), (0,s)(0,s), (s,0)(s,0), and (s,s)(s,s). In this game variation, nn identical balls are placed on the table with integral coordinates such that no ball lies on the edge or corner of the table. Then, they are all simultaneously shot at 1010010^{100} units/sec speed (only at 4545 degrees with the axes).

In universe AX120, balls and pockets are almost point-sized, and the collisions are elastic, i.e., the ball, on hitting any surface, bounces off at the same angle and with the same speed.

Harshith shot the balls, and he provided Aryan with the balls' positions and the angles at which he shot them. Help Aryan determine the number of balls potted into the pockets by Harshith.

It is guaranteed that multiple collisions do not occur at the same moment and position.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t10001 \le t \le 1000). The description of the test cases follows.

The first line of each test case contains two integers nn and ss (1n1031 \le n \le 10^3, 2s1092 \le s\le 10^9) — the number of balls placed on the table and the side length of the square pool table.

The ii-th of the next nn lines contains four integers dxd_x, dyd_y, xix_i, and yiy_i (dx,dy{1,1}d_x,d_y \in \{-1, 1\}, 0<xi,yi<s0 \lt x_i, y_i \lt s) — the direction vectors of the launch on the XX-axis and YY-axis respectively, and the coordinates of the location where the ii-th ball was placed. It is guaranteed that no two balls coincide at the initial moment.

It is also guaranteed that the sum of nn over all test cases does not exceed 10310^3.

Output

For each test case, print a single integer — the number of balls potted in that game.

Note

In the first test case, there is a single ball and it's shot directly towards the pocket at (2,2)(2, 2), thus potted.

In the second test case, the state progresses as

\rightarrow
\rightarrow
\rightarrow
\rightarrow

Samples

2
1 2
1 1 1 1
5 4
1 -1 1 1
1 -1 2 2
-1 1 2 3
1 -1 1 3
-1 1 3 1
1
3

在线编程 IDE

建议全屏模式获得最佳体验