Chef and Polyhedron

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef likes stereometry a lot. Recently he learned about polyhedrons. During his assignments, he found a problem which he couldn't solve. Can you please help him in solving the problem?
You are given a convex polyhedron. Each face of polyhedron is a regular polygon. All polyhedral angles are equal. You have to find number of different ways to paint all the faces of the polyhedron in one of the C colors. Note that two painting of the polyhedron are said to be same, if one can be reached from other by a sequence of rotations or mirror reflections of the polyhedron. As this value could be large, output it by modulo 10^{9}+7.
Input
There is a single test case.
First line of the input contains two positive integers  N (number faces of the polyhedron) and C (number of possible colors)
Next N lines contain information about the faces of polyhedron:
First number of each line contains an integer k_{i} denoting number of faces adjacent to ith face. Next k_{i} integers in the same line denote the faces adjacent to ith face.
Output
Output a single integer in a line denoting number of ways to color polyhedron in different ways modulo 10^{9}+7
Constraints
 4 ≤ N ≤ 25
 1 ≤ C ≤ 10^{9}
Subtasks
 Subtask 1: Polyhedron is regular. Points  20
 Subtask 2: Original constraints. Points  80
Example
Input: 6 2 4 2 3 4 5 4 1 3 5 6 4 1 2 4 6 4 1 3 5 6 4 1 2 4 6 4 2 3 4 5 Output: 10
Input: 4 4 3 2 3 4 3 1 3 4 3 1 2 4 3 1 2 3 Output: 35
Author:  mgch 
Tester:  mugurelionut 
Editorial  http://discuss.codechef.com/problems/CHEFPOL 
Tags  burnside hard july16 mgch 
Date Added:  21062016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 4.9.2, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.4, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC 
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. 