#include<bits/stdc++.h>
using namespace std;
string A,B;
string ch1[10],ch2[10];
map<string,int>mm1,mm2;
int len;
struct node{
node(){}
node(string s1,int step1){
str=s1;
step=step1;
}
string str;
int step;
};
queue<node>q1,q2;
int dbfs(){
while(!q1.empty() && !q2.empty()){
node cur,nex;
if(!q1.empty()){
cur = q1.front();
if(mm2[cur.str])
return cur.step+mm2[cur.str];
for(int i=0;i<len;i++){
nex=cur;
string r1 = ch1[i];
string r2 = ch2[i];
if(nex.str.find(r1)!=-1){
nex.str.replace(nex.str.find(r1),r1.size(),r2);
nex.step=cur.step+1;
if(mm2[nex.str])
return nex.step+mm2[nex.str];
if(!mm1[nex.str]){
q1.push(nex);
mm1[nex.str]=nex.step;
}
}
}
}
q1.pop();
if(!q2.empty()){
cur = q2.front();
if(mm1[cur.str])
return cur.step+mm1[cur.str];
for(int i=0;i<len;i++){
nex=cur;
string r1 = ch2[i];
string r2 = ch1[i];
if(nex.str.find(r1)!=-1){
nex.str.replace(nex.str.find(r1),r1.size(),r2);
nex.step=cur.step+1;
if(mm1[nex.str])
return nex.step+mm1[nex.str];
if(!mm2[nex.str]){
q2.push(nex);
mm2[nex.str]=nex.step;
}
}
}
}
q2.pop();
}
return 11;
}
int main(){
cin>>A>>B;
while(cin>>ch1[len]>>ch2[len]){
len++;
}
q1.push(node(A,0));
q2.push(node(B,0));
mm1[A]=1;
mm2[B]=1;
int k = dbfs();
if(k>10)
cout<<"NO ANSWER!";
else
cout<<k;
return 0;
}