program llk;
const
max=10;
maxn=10;
maxturn=2;
filein='llkin.txt';
fileout='llkout.txt';
var
pmap,map:array [-1..max+2,-1..max+2] of byte;
fa,fb,ea,eb:array [1..5*max] of byte;
sa,sb,long,wide,n,fp,p:integer;
tx:text;
procedure first;
var t:text;
i,j:integer;
begin
assign(t,filein);
reset(t);
read(t,long,wide,n);
fillchar(map,sizeof(map),0);
for i:=1 to wide do
for j:=1 to long do
read(t,map[i,j]);
close(t);
fp:=1;
end;
procedure searcha(a,b,nn,o:integer);
var j:integer;
begin
if (nn>maxturn) then exit;
j:=a+1;
while (map[j,b]= 0)and (j<=wide+1) do
begin
if pmap[j,b]>nn then pmap[j,b]:=nn;
searchb(j,b,nn+1,o);
j:=j+1
end;
if map[j,b]=o then
begin
fa[fp]:=j;
fb[fp]:=b;
markone
end;
j:=a-1;
while (map[j,b]= 0)and (j>=0) do
begin
if pmap[j,b]>nn then pmap[j,b]:=nn;
searchb(j,b,nn+1,o);
j:=j-1
end;
if map[j,b]=o then
begin
fa[fp]:=j;
fb[fp]:=b;
markone
end;
end;
procedure searchb(a,b,nn,o:integer);
var i:integer;
begin
if (nn>maxturn) or (fa[fp]>0)and(fb[fp]>0) then exit;
i:=b+1;
while (map[a,i]= 0)and (i<=long+1) do
begin
if pmap[a,i]>nn then pmap[a,i]:=nn;
searcha(a,i,nn+1,o);
i:=i+1
end;
if map[a,i]=o then
begin
fa[fp]:=a;
fb[fp]:=i;
markone
end;
i:=b-1;
while (map[a,i]= 0)and (i>=0) do
begin
if pmap[a,i]>nn then pmap[a,i]:=nn;
searcha(a,i,nn+1,o);
i:=i-1
end;
if map[a,i]=o then
begin
fa[fp]:=a;
fb[fp]:=i;
markone
end;
end;
procedure output(ob:integer);
begin
if fp=0 then exit;
write(tx,ob,' : ');
while fp>1 do
begin
fp:=fp-1;
write(tx,ea[fp],'.',eb[fp],'-',fa[fp],'.',fb[fp],' ')
end;
writeln(tx);
end;
procedure markone;
var fp2:integer;
begin
for fp2:=1 to fp-1 do
if (fa[fp2]=fa[fp])and(fb[fp2]=fb[fp]) then
if (ea[fp2]=sa)and(eb[fp2]=sb) then
begin fa[fp]:=0;fb[fp]:=0;exit end;
ea[fp]:=sa;
eb[fp]:=sb;
fp:=fp+1;
end;
procedure work(point:integer);
begin
for sa:=1 to wide do
for sb:=1 to long do
if map[sa,sb]=point then
begin
searcha(sa,sb,0,point);
searchb(sa,sb,0,point);
{if (fa[fp]=0)or(fb[fp]=0) then exit
else begin
ea[fp]:=sa;eb[fp]:=sb;fp:=fp+1 end;}
end;
output(point);
end;
begin
first;
assign(tx,fileout);
rewrite(tx);
for p:=1 to n do
begin
fillchar(pmap,sizeof(pmap),1);
fillchar(fa,sizeof(fa),0);
fillchar(fb,sizeof(fb),0);
work(p);
end;
close(tx);
end.
program llk;
const
max=100;
maxn=30;
maxturn=2;
filein='llkin.txt';
var
pmap,map:array [-1..max+2,-1..max+2] of byte;
fa,fb,ea,eb:array [1..5*max] of byte;
sa,sb,long,wide,n,fp,p:integer;
procedure first;
var t:text;
i,j:integer;
begin
assign(t,filein);
reset(t);
read(t,long,wide,n);
fillchar(map,sizeof(map),0);
for i:=1 to wide do
for j:=1 to long do
read(t,map[i,j]);
close(t);
fp:=1;
end;
procedure searcha(a,b,nn,o:integer);
var j:integer;
begin
if (nn>maxturn) then exit;
j:=a+1;
while (map[j,b]= 0)and (j<=long+1) do
begin
if pmap[j,b]>nn then pmap[j,b]:=nn;
searchb(j,b,nn+1,o);
j:=j+1
end;
if map[j,b]=o then
begin
fa[fp]:=j;
fb[fp]:=b;
markone
end;
j:=a-1;
while (map[j,b]= 0)and (j>=0) do
begin
if pmap[j,b]>nn then pmap[j,b]:=nn;
searchb(j,b,nn+1,o);
j:=j-1
end;
if map[j,b]=o then
begin
fa[fp]:=j;
fb[fp]:=b;
markone
end;
end;