#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; map dv(ll x){ map rt; ll cx=x; for(ll i=2;i*i<=x;i++){ while(cx%i==0){ cx/=i; rt[i]++; } } if(cx>1) rt[cx]++; return rt; } int main(){ int n,m; cin>>n>>m; vector v(n); rep(i,n) v.at(i)=i; rep(i,m){ int t; cin>>t; vector s(t); rep(i,t) cin>>s.at(i),s.at(i)--; int bf=v.at(s.at(0)); for(int i=t-1;i>=0;i--){ v.at(s.at((i+1)%t))=v.at(s.at(i)); } v.at(s.at(1))=bf; } atcoder::dsu uf(n); rep(i,n) uf.merge(i,v.at(i)); map mp; rep(i,n) mp[uf.leader(i)]++; const int MOD = 998244353; map st; for(auto[ii,sz]:mp){ map d=dv(sz); for(auto[i,x]:d){ if(st[i]