#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 mint tp = 1; void Gauss(vector> &A){ if(A.size()==0)return; int last = 0; rep(i,A[0].size()){ int ind = -1; for(int j=last;j>N>>K; vector>> t(K); rep(i,K){ int tt; cin>>tt; t[i].resize(tt); rep(j,tt){ cin>>t[i][j].first>>t[i][j].second; t[i][j].first--; t[i][j].second--; } } mint ans = 0; rep(i,1<> a(N,vector(N,0)); rep(j,K){ if((i>>j)&1){ rep(k,t[j].size()){ int u = t[j][k].first,v = t[j][k].second; a[u][u]++; a[v][v]++; a[u][v]--; a[v][u]--; } } } a.pop_back(); rep(j,N-1)a[j].pop_back(); tp = 1; Gauss(a); tp = tp.inv(); if(a.size()!=N-1)tp = 0; else{ rep(j,N-1){ tp *= a[j][j]; } } if(K%2 != __builtin_popcount(i)%2)tp *= -1; ans += tp; } cout<