const int MAXN=505;
char buf[MAXN][MAXN];
int main()
{
int T=read_int();
while(T--){
int n=read_int(),m=read_int();
_for(i,0,n)scanf("%s",buf[i]);
int s1,s2;
if(n%3==1){
s1=0;
s2=2;
}
else{
s1=1;
s2=3;
}
for(int i=s1;i
const int MAXN=405,MAXM=605,Mod=998244353;
struct Edge{
int to,next;
}edge[MAXM<<1];
int head[MAXN],edge_cnt,dis[MAXN][MAXN];
void Insert(int u,int v){
edge[++edge_cnt]=Edge{v,head[u]};
head[u]=edge_cnt;
}
int main()
{
int n=read_int(),m=read_int();
mem(dis,127/3);
_rep(i,1,n)dis[i][i]=0;
_for(i,0,m){
int u=read_int(),v=read_int();
dis[u][v]=dis[v][u]=1;
Insert(u,v);Insert(v,u);
}
_rep(k,1,n)_rep(i,1,n)_rep(j,1,n)
dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
_rep(x,1,n){
_rep(y,1,n){
int ans=1,cnt=0;
_rep(u,1,n){
if(dis[x][u]+dis[u][y]==dis[x][y])cnt++;
else{
int cnt2=0;
for(int i=head[u];i;i=edge[i].next){
int v=edge[i].to;
if(dis[x][u]==dis[x][v]+1&&dis[y][u]==dis[y][v]+1)
cnt2++;
}
ans=1LL*ans*cnt2%Mod;
}
}
space(cnt==dis[x][y]+1?ans:0);
}
puts("");
}
return 0;
}
const int MAXN=5e6+5,Mod=1e9+7;
int seed,base;
int rnd(){
int ret=seed;
seed=(1LL*seed*base+233)%Mod;
return ret;
}
int a[MAXN],b[MAXN],t[MAXN];
LL s[2];
int main()
{
int n=read_int(),m=read_int(),pos=0;
_for(i,0,m){
int p=read_int(),k=read_int();
seed=read_int();
base=read_int();
while(pos
typedef set::iterator iter;
const int MAXN=2e5+5;
struct Edge{
int to,next;
}edge[MAXN];
int head[MAXN],edge_cnt;
void Insert(int u,int v){
edge[++edge_cnt]=Edge{v,head[u]};
head[u]=edge_cnt;
}
int st[MAXN],tp,p[MAXN],a[MAXN],b[MAXN],cnt[MAXN];
LL c[MAXN],dp[MAXN];
bool vis[MAXN];
namespace LCA{
int d[MAXN],sz[MAXN],f[MAXN];
int h_son[MAXN],mson[MAXN],p[MAXN];
LL dis[MAXN];
void dfs_1(int u,int fa,int depth){
sz[u]=1;f[u]=fa;d[u]=depth;mson[u]=0;
dp[u]=c[u];
for(int i=head[u];i;i=edge[i].next){
int v=edge[i].to;
dfs_1(v,u,depth+1);
dp[u]+=min(dp[v],0LL);
sz[u]+=sz[v];
if(sz[v]>mson[u])
h_son[u]=v,mson[u]=sz[v];
}
}
void dfs_2(int u,int top){
p[u]=top;
if(mson[u])dfs_2(h_son[u],top);
for(int i=head[u];i;i=edge[i].next){
int v=edge[i].to;
if(v==h_son[u])
continue;
dfs_2(v,v);
}
}
void dfs_3(int u){
dis[u]+=max(dp[u],0LL);
for(int i=head[u];i;i=edge[i].next){
int v=edge[i].to;
dis[v]+=dis[u];
dfs_3(v);
}
}
void init(int root){
dfs_1(root,-1,0);
dfs_2(root,root);
for(int i=head[root];i;i=edge[i].next)
dfs_3(edge[i].to);
}
int query_lca(int u,int v){
while(p[u]!=p[v]){
if(d[p[u]] s;
s.insert(0);
cnt[0]++;
LL ans=0;
while(q--){
int u=read_int(),p=LCA::f[u];
if(!vis[u]){
cnt[p]++;
if(cnt[p]==1){
iter rig=s.upper_bound(p);
iter lef=--rig;
rig++;
rig=(rig==s.end())?s.begin():rig;
ans+=LCA::query_dis(p,*rig);
ans-=LCA::query_dis(*lef,*rig);
ans+=LCA::query_dis(*lef,p);
s.insert(p);
}
}
else{
cnt[p]--;
if(cnt[p]==0){
iter rig=s.find(p);
iter lef=--rig;
rig++;rig++;
rig=(rig==s.end())?s.begin():rig;
ans-=LCA::query_dis(p,*rig);
ans+=LCA::query_dis(*lef,*rig);
ans-=LCA::query_dis(*lef,p);
s.erase(p);
}
}
vis[u]=!vis[u];
enter(dp[0]+ans/2);
}
return 0;
}