#include<bits/stdc++.h>
using namespace std;
string a1,b1;
string str[10],str2[10];
int n=1;
struct node{
int step;
string zx;
};
queue<node> q;
set<string> s;
int main(){
cin>>a1>>b1;
while(cin>>str[n]>>str2[n])
{
n++;
}
if(a1==b1)
{
cout<<0<<endl;
return 0;
}
node cc;
cc.step=0;
cc.zx=a1;
q.push(cc);
s.insert(a1);
while(!q.empty())
{
int stepp=q.front().step;
string zxx=q.front().zx;
if(stepp>10)
{
cout<<"NO ANSWER!"<<endl;
return 0;
}
for(int i=1;i<=n;i++)
{
if(zxx.find(str[i])==-1)
{
continue;
}else
{
string ss=zxx;
ss.replace(zxx.find(str[i]),str[i].length(),str2[i]);
if(s.count(ss)==0)
{
node cc2;
cc2.step=stepp+1;
cc2.zx=ss;
q.push(cc2);
s.insert(ss);
}
if(ss==b1)
{
cout<<stepp+1<<endl;
return 0;
}
}
}
q.pop();
}
cout<<"NO ANSWER!"<<endl;
return 0;
}