Pairwise union of sets

All submissions for this problem are available.
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 ith 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.
Example
Input 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 Output 0 3 3
Explanation
Example 1. No pair of sets is there with its union = 2.
For example 2 and 3, all the pairs are valid.
Author:  admin2 
Editorial  https://discuss.codechef.com/problems/UNIONSET 
Tags  admin2, june17, medium 
Date Added:  2062017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 