Maze
题号:NC202149
时间限制:C/C++/Rust/Pascal 4秒,其他语言8秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

As the title implies, your task in this problem is related to maze, specifically a 2D maze of rows and columns (), where rows are numbered from to from top to bottom, and columns are numbered from 1 to from left to right. The cell at the i-th row and the j-th column is denoted by .
The maze has only one entry which is at and only one exit which is at . To simplify things, you are only allowed to move right or down at any step. There might be cells with obstacle which cannot be visited, and there might be cells with treasure which must be visited.
In this problem, you are requested to count the number of valid paths from the starting location to the ending location.
There are cells with treasure. The valid path should visit all cells with treasure.
The following cells with obstacle, the valid path cannot visit any cell with obstacle.
  • all cells meet ,
  • all cells meet ,
  • and there are additional cells with obstacle.

输入描述:

The first line of the input gives the number of test case,  ().  test cases follow.
Each test case consists of one line with four integers , , , and as described above. (, , )
Then, lines follow. Each line consists of integers and , indicating the cells with treasure in the maze. (, , , ) (no two cells are in the same position)
After that, there are lines. Each line consists of integers and , indicating the cells with obstacle in the maze. (, , , ) (no two cells are in the same position)

输出描述:

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the number of valid paths module 1,000,000,007 ().
示例1

输入

复制
2
2 3 0 0
3 6 1 1
2 4
1 3

输出

复制
Case #1: 1
Case #2: 2

说明

In Sample Case #1, one valid path are:


In Sample Case #2, two valid paths are: