Fishing Game

Time limit: 1.3s Memory limit: 512MB Input: Output:

Fishing is a card game that is played with a deck of cards consisting of 3N3N pairs of cards, numbered from 11 to 3N3N (the deck contains 6N6N cards overall).

Three friends (A,BA, B and CC) play Fishing. The rules are as follows:

  1. Initially, each player receives 2N2N cards.
  2. Then, each player discards all same-value pairs of cards they have.
  3. Rounds consisting of three steps are played until all remaining cards get discarded:
    • a) AA passes one of his cards to BB (unless AA doesn't have any). If BB now has a pair of same-value cards, it gets discarded.
    • b) BB passes one of his cards to CC (unless BB doesn't have any). If CC now has a pair of same-value cards, it gets discarded.
    • c) CC passes one of his cards to AA (unless CC doesn't have any). If AA now has a pair of same-value cards, it gets discarded.

Task

You are given the hands of the three players at the end of step (1) . It's known that at least one pair of same-value cards has to be discarded during each round described at point (3).

Compute the number of different ways the game can play out. Since this number can be quite large, output it modulo 1 000 000 0071 \ 000 \ 000 \ 007.

Input data

The first line of input contains two integers NN and TT, where TT is the number of game scenarios to analyse.

The description of TT game scenarios follows. Each game scenario consists of three lines:

  • The first line contains 2N2N card values - player AA's hand at the end of step (1).
  • The second line contains 2N2N card values - player BB's hand at the end of step (1).
  • The third line contains 2N2N card values - player CC's hand at the end of step (1).

Output data

For each game scenario, print the number of different ways the game can play out modulo 1 000 000 0071 \ 000 \ 000 \ 007 on a separate line.

Constraints and clarifications

  • 1N<1001 \leq N < 100
  • 1T101 \leq T \leq 10
  • Two ways the game can play out are considered different if during one step the current player chooses to pass a different card.
# Points Restrictions
1 10 N=2, T=3N = 2, \ T = 3
2 10 N=3, T=5N = 3, \ T = 5
3 10 N=10, T=5N = 10, \ T = 5
4 10 N=20, T=5N = 20, \ T = 5
5 10 N=50, T=10N = 50, \ T = 10
6 10 N=60, T=10N = 60, \ T = 10
7 10 N=70, T=10N = 70, \ T = 10
8 10 N=80, T=10N = 80, \ T = 10
9 10 N=90, T=10N = 90, \ T = 10
10 10 N=99, T=10N = 99, \ T = 10

Example

stdin

1 1
1 2
3 3
2 1

stdout

2

Explanation

First, during step (2) , player BB discards all their cards. At this point, the players' hands are:

  • A: 1,2A: \ 1, 2
  • B:B: no cards
  • C: 1,2C: \ 1, 2

There are two ways the game can play out from this point:

  1. AA passes card 11 to BB. Then, BB passes it to CC. This way, CC discards the pair of cards with value 11. Then, CC has to pass his remaining card to AA, who discards it.
  2. AA passes card 22 to BB. Then, BB passes it to CC. This way, CC discards the pair of cards with value 22. Then, CC has to pass his remaining card to AA, who discards it.

Log in or sign up to be able to send submissions!