#include <iostream>
using namespace std;
bool pd[41][41];
int s[41][41];
bool use[41];
int num[41];
int c,n,z;
int d[10000][41];
void print()
{
printf("%d %d\n",c,z);
int i,j;
for (i=1;i<=z;i++)
{
for (j=1;j<=n;j++)
printf("%d ",d[i][j]);
printf("\n");
}
}
void dfs(int i)
{
int j,p;
for (j=1;j<=s[num[i-1]][0];j++)
{
if (use[s[num[i-1]][j]])
{
if (!(i==2&&s[num[i-1]][j]==n))
{
use[s[num[i-1]][j]]=false;
num[i]=s[num[i-1]][j];
if (i==n&&pd[num[n]][1])
{
if (num[2]<num[n])
{
++z;
for (p=1;p<=n;p++)
d[z][p]=num[p];
}
}
else
dfs(i+1);
use[s[num[i-1]][j]]=true;
}
}
}
}
void start()
{
freopen("dislike.in","r",stdin);
freopen("dislike.out","w",stdout);
c=1;
while (c!=0)
{
scanf("%d%d",&c,&n);
if (c!=0)
{
int i,j,t;
for (i=1;i<=n;i++)
for (j=0;j<=n;j++)
{
pd[i][j]=false;
s[i][j]=0;
}
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
scanf("%d",&t);
if (t==0)
pd[i][j]=true;
}
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
if ((pd[i][j]==true)&&(pd[j][i]==true))
{
s[i][0]++;
s[i][s[i][0]]=j;
}
else
{
pd[i][j]=false;
pd[j][i]=false;
}
}
for (i=1;i<=n;i++)
use[i]=true;
z=0;
num[1]=1;
use[1]=false;
dfs(2);
print();
}
}
}
int main()
{
start();
return 0;
}