#include<cstdio>
#include<cstring>#include<iostream>
using namespace std;
const int MAXN= 6;
const int inf=1<<30;
int n, m,cas=1;
bool pat[3][3];
int path[MAXN*MAXN], mat[MAXN], mm;
void read()
{
memset(mat,0, sizeof(mat));
for(int i=0; i<3; ++i)
{
for(int j=0; j<3; ++j)
{
pat[i][j]=0;
pat[i][j] = getchar()=='*'?1:0;
}
getchar();
}
}
int ok(int r)
{
if(mat[r]==(1<<m)-1)return 1;
return 0;
}
int check()
{
if(n>1 && ok(n-1) && ok(n-2) ||
n==1 && ok(0))
return 1;
return 0;
}
void cover(int x,int y)
{
int i,j;
for(i=x-1;i<=x+1;i++)
{
if(i<0||i>=n)
continue;
for(j=y-1;j<=y+1;j++)
{
if(j<0||j>=m)
continue;
if(pat[i-x+1][j-y+1])
mat[i]^=(1<<j);
}
}
}
int dfs(int cur,int step)
{
int r=cur/m,c=cur-r*m;
if(r>=2&&!ok(r-2))return 0;
if(cur==m*n)
{
if(check())
{
mm=step;
return 1;
}
return 0;
}
if(dfs(cur+1,step))return 1;
cover(r,c);
path[step]=cur+1;
if(dfs(cur+1,step+1))return 1;
cover(r,c);
return 0;
}
int main()
{
while(~scanf("%d%d",&n,&m),(n&&m))
{
getchar();
memset(path,0,sizeof(path));
read();
mm=inf;
printf("Case #%d\n", cas++);
if(dfs(0,0))
{
cout<<path[0];
for(int i=1;i<mm;i++)
{
cout<<" "<<path[i];
}cout<<endl;
}else puts("Impossible.");
}
return 0;
}
/*
2 3
**.
.*.
*..
*/