#include #include #include using namespace std; using namespace atcoder; using mint = modint; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 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>_t; rep(_,_t){ int N,P; cin>>N>>P; mint::set_mod(P); vector> a(N,vector(N)); rep(i,N){ rep(j,N){ cin>>a[i][j]; } } if(P!=2){ cout<<0< xs(N),ys(N); bool f = true; int c = 0; rep(i,N){ rep(j,N){ if(a[i][j]==-1){ if(xs[i]||ys[j])f = false; xs[i] = 1; ys[j] = 1; c++; } } } if(!f){ cout<<0<> b(N-c,vector(N-c)); int ii = 0; rep(i,N){ if(xs[i])continue; int jj = 0; rep(j,N){ if(ys[j])continue; b[ii][jj] = a[i][j]; jj++; } ii++; } Gauss(b); if(b.size()!=N-c)cout<<0<