Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin, Russian and Vietnamese as well. 

There are N sets of integers from 1 to K both inclusive. Find out number of pairs of sets whose union contains all the K elements.

------ Input ------ 

The first line contains an integer T denotes number of test cases.
The first line of each test case contains two space separated integers N, K.
The each of the next line first contains an integer len_{i} denoting number of elements in the i-th set, followed by len_{i} space separated integers in the range [1, K] denoting the elements in the set.

------ Output ------ 

For each test case, output a single integer corresponding to the answer.

------ Constraints ------ 

$1 ≤ T ≤ 10$
$1 ≤ N, K ≤ 2500$
$1 ≤ len_{i} ≤ K$
$Note that a set can't contain repeated elements.$
$1 ≤ len_{1} + len_{2} + .. + len_{N} ≤ 10000$

------ Subtasks ------ 

Subtask #1 (40 points)

$1 ≤ T ≤ 10$
$1 ≤ N, K ≤ 250$
$1 ≤ len_{1} + len_{2} + .. + len_{N} ≤ 1000$

Subtask #2 (60 points)

$original constraints.$

----- Sample Input 1 ------ 
3
2 2
1 1
1 1
3 2
2 1 2
2 1 2
2 1 2
3 4
3 1 2 3
4 1 2 3 4
3 2 3 4
----- Sample Output 1 ------ 
0
3
3
----- explanation 1 ------ 
Example 1. No pair of sets is there with its union = 2.
For example 2 and 3, all the pairs are valid.