#include #include using namespace std; using ll = long long; #define rep(i,n) for(int i=0;i<(int)(n);i++) using mint = atcoder::modint998244353; int n; using mat=vector>; void tri(mat &a){ rep(i,n-1){ if(a.at(i).at(i)==0){ for(int j=i+1;j>n>>k; vector g(k,mat(n,vector(n,0))); rep(i,k){ int t; cin>>t; rep(lp,t){ int a,b; cin>>a>>b; a--; b--; g.at(i).at(a).at(a)++; g.at(i).at(b).at(b)++; g.at(i).at(a).at(b)--; g.at(i).at(b).at(a)--; } } mint ans=0; rep(bit,(1<(n,0)); rep(i,k){ if(bit>>i&1){ rep(j,n) rep(k,n) ad.at(j).at(k)+=g.at(i).at(j).at(k); } } tri(ad); mint tmp=1; rep(i,n-1) tmp*=ad.at(i).at(i); if(__builtin_popcount(bit)%2) ans+=tmp; else ans-=tmp; } cout<