#P6639. Faraway
Faraway
Problem Description
$n$ soldiers are dispatched to somewhere in Byteland. These soldiers are going to set off now, but the target location is not so clear.
Assume the target location is at $(x_e,y_e)$, it is clear that $x_e,y_e$ are both non-negative integers within $[0,m]$. For the $i$-th soldier, the only thing he knows is that $(|x_i-x_e|+|y_i-y_e|)\bmod k_i=t_i$.
To find the correct target location, these soldiers are working on the information they have now. Please write a program to figure out the number of possible target locations.
Input
The first line of the input contains an integer $T(1\leq T\leq 10)$, denoting the number of test cases.
In each test case, there are two integers $n,m(1\leq n\leq 10,1\leq m\leq 10^9)$ in the first line, denoting the number of soldiers and the upper bound of $x_e,y_e$.
For the next $n$ lines, each line contains four integers $x_i,y_i,k_i,t_i(0\leq x_i,y_i\leq m,2\leq k_i\leq 5,0\leq t_i<k_i)$, denoting what each soldier knows.
Output
For each test case, print a single line containing an integer, denoting the number of possible target locations.
2
2 5
1 2 4 2
3 1 2 1
2 5
1 2 4 2
1 2 4 3
10
0