type think=record
x,y:string;
end;
var a,b,s:string;
k:longint;
max:longint;
f:array[0..1,1..1000] of think;
head,tail:array[0..1] of longint;
father:array[0..1,1..1000] of longint;
c:array[0..1,1..1000] of string;
procedure init;
var i,p:longint;
begin
k:=0;
readln(s);
p:=pos(' ',s);
a:=copy(s,1,p-1);
b:=copy(s,p+1,length(s)-p);
while not eof do
begin
readln(s);
p:=pos(' ',s);
inc(k);
f[0,k].x:=copy(s,1,p-1);
f[0,k].y:=copy(s,p+1,length(s)-p);
f[1,k].y:=copy(s,1,p-1);
f[1,k].x:=copy(s,p+1,length(s)-p);
end;
end;
function chong(t,p:longint):boolean;
var i:longint;
begin
chong:=false;
for i:=1 to t-1 do
if c[p,i]=c[p,t] then exit(true);
end;
procedure ok(p:integer);
var i,j:longint;
begin
if p=0 then
for i:=tail[1] downto 1 do
if c[1,i]=c[0,tail[0]] then
if father[1,i]+father[0,tail[0]]<=10 then begin writeln(father[1,i]+father[0,tail[0]]);halt;end
else begin writeln('NO ANSWER!');halt;end;
if p=1 then
for j:=tail[0] downto 1 do
if c[0,j]=c[1,tail[1]] then
if father[0,j]+father[1,tail[1]]<=10 then begin writeln(father[0,j]+father[1,tail[1]]);halt;end
else begin writeln('NO ANSWER!');halt;end;
end;
procedure expand(p:longint);
var i,d:longint;
s:string;
begin
inc(head[p]);
s:=c[p,head[p]];
for i:=1 to k do
if pos(f[p,i].x,s)>0 then begin
inc(tail[p]);
father[p,tail[p]]:=father[p,head[p]]+1;
d:=pos(f[p,i].x,s);
c[p,tail[p]]:=s;
delete(c[p,tail[p]],d,length(f[p,i].x));
insert(f[p,i].y,c[p,tail[p]],d);
if chong(tail[p],p) then dec(tail[p]);
ok(p);
end;
end;
begin
assign(input,'input.in');
reset(input);
init;
max:=10;
fillchar(head,sizeof(head),0);
fillchar(c,sizeof(c),0);
tail[0]:=1;
tail[1]:=1;
c[0,1]:=a;
c[1,1]:=b;
repeat
if (head[1]<head[0]) and(tail[1]<tail[0])and(tail[1]<max) then expand(1);
if (head[0]<=head[1]) and(tail[0]<=tail[1])and(tail[0]<=max) then expand(0);
if (head[0]<=tail[0])and(tail[0]<=max) then expand(0);
if (head[1]<=tail[1])and(tail[1]<=max) then expand(1);
until (head[0]>tail[0])or(tail[0]>max)or(head[1]>tail[1])or(tail[1]>max);
writeln('NO ANSWER!');
close(input);
end.