You are given a grid with 7 columns and N rows (numbered from 1 to N). 4 players will start their journey in that grid. Initially all of them are in the first row. A player can move diagonally to the next row. For example, a player is in row 3 and column 4, which can also be represented as (3, 4), this player has only two valid moves, (4, 3) and (4, 5). But if the player is in (3, 1), he has only one valid move, which is (4, 2). In their journey, any cell of the grid cannot be visited by more than one player.
In this problem you have to find, in how many ways all of the players can reach the Nth row.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains an integer N (1 ≤ N < 231) in a line. The next line will contain 7 integers, which represent the state of first row. ri = 0 represents that, there is no player in row i, otherwise ri will represent the player number. You can assume that there will be exactly 4 players and are numbered from 1 to 4.
Output
For each case, print the case number and number of ways to reach the Nth row. You have to print the result modulo 1000000007 (109 + 7).
Sample
Sample Input | Sample Output |
---|---|
3 1 1 0 2 0 3 0 4 2 1 0 2 0 3 0 4 2 1 2 3 4 0 0 0 | Case 1: 1 Case 2: 0 Case 3: 3 |