Input1
ANA
ANA
DAR
DAR
RAD
RAD
Input2
EVO
HEP
HIR
IVA
PAD
ROD
Input3
AKO
CES
DOC
DON
ESI
KES
var
a,b,c,i,j,k,i1,j1,ans:longint;
s:array[1..6]of string;
p:array[1..6]of boolean;
t:array[0..46657]of string;
procedure ss(l,r:longint);
var
i,j:longint;
mid:string;
begin
i:=l;
j:=r;
mid:=t[(i+j)div 2];
while i<j do
begin
while t[i]<mid do inc(i);
while t[j]>mid do dec(j);
if i<=j then
begin
t[0]:=t[i];
t[i]:=t[j];
t[j]:=t[0];
inc(i);
dec(j);
end;
end;
if j>l then ss(l,j);
if i<r then ss(i,r);
end;
begin
assign(input,'match.in');reset(input);
assign(output,'match.out');rewrite(output);
for a:=1 to 6 do
readln(s[a]);
for a:=1 to 6 do
begin
p[a]:=true;
for i:=1 to 6 do
begin
if p[i]=true then
continue;
if s[i][1]<>s[a][1] then continue;
p[i]:=true;
for j:=1 to 6 do
begin
if p[j]=true then
continue;
if s[j][1]<>s[a][2] then
continue;
p[j]:=true;
for k:=1 to 6 do
begin
if p[k]=true then
continue;
if s[k][1]<>s[a][3] then
continue;
p[k]:=true;
for i1:=1 to 6 do
begin
if p[i1]=true then
continue;
if (s[i1][1]<>s[i][2])
or(s[i1][2]<>s[j][2])
or(s[i1][3]<>s[k][2]) then
continue;
p[i1]:=true;
for j1:=1 to 6 do
begin
if p[j1]=true then
continue;
if (s[j1][1]<>s[i][3])
or(s[j1][2]<>s[j][3])
or(s[j1][3]<>s[k][3]) then
continue;
inc(ans);
t[ans]:=s[i]+s[j]+s[k];
end;
p[i1]:=false;
end;
p[k]:=false;
end;
p[j]:=false;
end;
p[i]:=false;
end;
p[a]:=false;
end;
if ans=0 then
begin
writeln(0);
halt;
end;
ss(1,ans);
writeln(t[1][1],t[1][2],t[1][3]);
writeln(t[1][4],t[1][5],t[1][6]);
writeln(t[1][7],t[1][8],t[1][9]);
close(input);
close(output);
end.