/**
动态规划(数塔问题)
*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#define maxn 1005
#define INF 0x3fffffff
using namespace std;
int mp[maxn][maxn];
int path[maxn][maxn];
int index(int x,int y){
if(mp[x-1][y-1]<mp[x-1][y]&&mp[x-1][y-1]<mp[x-1][y+1])
return y-1;
else if(mp[x-1][y]<mp[x-1][y+1])
return y;
return y+1;
}
int re[maxn];
int main(){
int n,m,T;
scanf("%d",&T);
int ii=1;
while(T--){
scanf("%d%d",&n,&m);
for(int i=0;i<maxn;i++) mp[n+1][i]=mp[i][m+1]=mp[i][0]=mp[0][i]=INF;
memset(path,-1,sizeof(path));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&mp[i][j]);
for(int i=2;i<=n;i++){
for(int j=1;j<=m;j++){
path[i][j]=index(i,j);
mp[i][j]+=mp[i-1][path[i][j]];
}
}
int ans=m;
for(int i=m-1;i>=1;i--){
if(mp[n][i]<mp[n][ans]) ans=i;
}
int cor=0;
for(int i=n;i>=1;i--){
re[cor++]=ans;
ans=path[i][ans];
}
printf("Case %d\n",ii++);
for(int i=n-1;i>=0;i--){
if(i==n-1) printf("%d",re[i]);
else printf(" %d",re[i]);
}
printf("\n");
}
return 0;
}