ICPCCamp teams are often selected by a mysterious (X,Y)-rule described in a blog (?).
There are (n+1) selection contests held to choose ICPCCamp team among m teams conveniently labeled with 1,2,…,m. The number of teams attending the i-th contest is k_i. As the last (the (n+1)-th) contest called EasyCamp-Final is very important, k_n+1=m always holds. The scoreboard of the i-th contest is r_i,1,r_i,2,…,r_i,k_i which indicates that team r_i,j has rank j in the contest.
The (X,Y)-rule works as follows. Firstly, two non-negative integers X and Y and a permutation P=p_1,p_2,…,p_n of 1,2,…,n are chosen. After that, the first X+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,… will be selected as ICPCCamp team. In other words, the list goes in the following order: the first Y EasyCamp-Final teams, then the top teams from the first n contests in the order defined by P, then the second teams from the first n contests in the same order, and so on.
Bobo would like to know the number of possible sets of ICPCCamp teams modulo (109+7) if he can choose X, Y and P 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 n and m (0≤n≤2⋅105, 1≤m≤2⋅105).
The i-th of following n lines contains an integer k_i followed by k_i integers r_i,1,r_i,2,…,r_i,k_i (1≤k_i≤m).
The last line contains m integers r_n+1,1,r_n+1,2,…,r_n+1,m (1≤r_i,j≤m, and for each i, the numbers r_i,1,r_i,2,…,r_i,k_i are distinct).
It is guaranteed that both the sum of k_i and the sum of m do not exceed 2⋅105.
For each test case, output an integer which denotes the number of sets modulo (109+7).