Welcome to ICPCCamp 2017

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

ICPCCamp teams are often selected by a mysterious (X,Y)(X, Y)-rule described in a blog (?). 

There are (n+1)(n + 1) selection contests held to choose ICPCCamp team among mm teams conveniently labeled with 1,2,,m1, 2, \dots, m. The number of teams attending the ii-th contest is k_ik\_i. As the last (the (n+1)(n + 1)-th) contest called EasyCamp-Final is very important, k_n+1=mk\_{n + 1} = m always holds. The scoreboard of the ii-th contest is r_i,1,r_i,2,,r_i,k_ir\_{i, 1}, r\_{i, 2}, \dots, r\_{i, k\_i} which indicates that team r_i,jr\_{i, j} has rank jj in the contest.

The (X,Y)(X, Y)-rule works as follows. Firstly, two non-negative integers XX and YY and a permutation P=p_1,p_2,,p_nP = \\{p\_1, p\_2, \dots, p\_n\\} of 1,2,,n\\{1, 2, \dots, n\\} are chosen.  After that, the first X+YX+Y distinct teams in the list r_n+1,1,r_n+1,2,,r_n+1,Y,r_p_1,1,r_p_2,1,,r_p_n,1,r_p_1,2,r_p_2,2,,r_p_n,2,\\{r\_{n + 1, 1}, r\_{n + 1, 2}, \dots, r\_{n + 1, Y}, r\_{p\_1, 1}, r\_{p\_2, 1}, \dots, r\_{p\_n, 1}, r\_{p\_1, 2}, r\_{p\_2, 2}, \dots, r\_{p\_n, 2}, \dots\\} will be selected as ICPCCamp team. In other words, the list goes in the following order: the first YY EasyCamp-Final teams, then the top teams from the first nn contests in the order defined by PP, then the second teams from the first nn contests in the same order, and so on.

Bobo would like to know the number of possible sets of ICPCCamp teams modulo (109+7)(10^9+7) if he can choose XX, YY and PP arbitrarily.

Wish you enjoy yourself in the upcoming World Finals!

입력

The input contains zero or more test cases, and is terminated by end-of-file. For each test case:

The first line contains two integers nn and mm (0n21050 \leq n \leq 2 \cdot 10^5, 1m21051 \leq m \leq 2 \cdot 10^5). 

The ii-th of following nn lines contains an integer k_ik\_i followed by k_ik\_i integers r_i,1,r_i,2,,r_i,k_ir\_{i, 1}, r\_{i, 2}, \dots, r\_{i, k\_i} (1k_im1 \leq k\_i \leq m).

The last line contains mm integers r_n+1,1,r_n+1,2,,r_n+1,mr\_{n + 1, 1}, r\_{n + 1, 2}, \dots, r\_{n + 1, m} (1r_i,jm1 \leq r\_{i, j} \leq m, and for each ii, the numbers r_i,1,r_i,2,,r_i,k_i\\{r\_{i, 1}, r\_{i, 2}, \dots, r\_{i, k\_i}\\} are distinct).

It is guaranteed that both the sum of k_ik\_i and the sum of mm do not exceed 21052 \cdot 10^5.

출력

For each test case, output an integer which denotes the number of sets modulo (109+7)(10^9+7).