This page is still under construction.

Parts of this page are still being built. What you see may change.

Your Ways

Time limit1sMemory limit128 MB

Summary
Count monotone lattice paths from (0,0) to (W,H) modulo 2552 for K days, where each day blocks up to 100 unit street/avenue segments with no two blocked segments on a common monotone path.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Math, Prefix sum
Solved
No attempts yet

Problem

You live in a small, well-planned rectangular town. Its central area measures HH kilometers by WW kilometers and is divided into H×WH \times W unit blocks, each of size 1×1 km21 \times 1\ \text{km}^2. There are H+1H + 1 streets running in the West-to-East direction and W+1W + 1 avenues running in the North-to-South direction, so the central area is a rectangle in the plane, as shown below.

Central area of the town

Figure 1. The central area of a town with H=3H = 3 and W=6W = 6.

Each intersection is identified by its coordinates in the plane. In the figure above, the bottom-left corner is intersection (0,0)(0, 0) and the top-right corner is intersection (6,3)(6, 3).

Your house is at the bottom-left corner (0,0)(0, 0) and you want to reach the university at the top-right corner (W,H)(W, H). To avoid wasting any effort, you only ever walk West-to-East or South-to-North. Walking this way, there are 8484 ways to reach the university in the example above.

You will go to the university for KK days. Each morning the city closes some parts of the streets and avenues for cleaning. The closures are always arranged so that no blocked part is reachable from another blocked part using only West-to-East and South-to-North walks; in other words, no single monotone route can pass through two blocked parts.

You still travel using only West-to-East and South-to-North moves. For each day, determine how many ways you can reach the university. Because the count can be very large, report it modulo 25522552.

Input

The first line contains an integer TT, the number of test cases (1≤T≤51 \le T \le 5). Each test case has the following format.

The first line of a test case contains three integers WW, HH, and KK (1≤W≤10001 \le W \le 1000; 1≤H≤10001 \le H \le 1000; 1≤K≤100001 \le K \le 10000). WW and HH give the size of the central area, and KK is the number of days you go to the university.

Each of the next KK lines describes the blocked parts for one day. Line ii (for 1≤i≤K1 \le i \le K) begins with an integer QiQ_i (1≤Qi≤1001 \le Q_i \le 100), the number of blocked parts, followed by QiQ_i groups of four integers. Each group AA, BB, CC, DD (0≤A≤C≤W0 \le A \le C \le W; 0≤B≤D≤H0 \le B \le D \le H) means that the part connecting intersection (A,B)(A, B) and intersection (C,D)(C, D) is blocked. Such a part is always a valid 11-km segment of a street or avenue, so C−A≤1C - A \le 1 and D−B≤1D - B \le 1.

Output

For each test case, for each day, print on its own line the number of ways to reach the university modulo 25522552. Hence the output for each test case consists of exactly KK lines.

Examples3

  1. Example 1

    Input
    2
    2 2 3
    1 0 0 0 1
    2 1 0 2 0 0 2 1 2
    1 1 1 2 1
    100 150 2
    1 99 150 100 150
    2 99 150 100 150 100 149 100 150
    
    Expected output
    3
    4
    4
    1562
    0
    
  2. Example 2

    Input
    1
    3 6 1
    1 0 0 1 0
    
    Expected output
    56
    
  3. Example 3

    Input
    1
    2 3 3
    1 0 0 1 0
    1 0 0 0 1
    1 2 2 2 3
    
    Expected output
    6
    4
    4