#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100,inf=160000;
struct node{
string s;
int step;
};
queue <node> q;
string a,b;
string s1[N],s2[N];
int l=1,l1,l2;
void bfs()
{
q.push({a,0});
while(!q.empty())
{
node h=q.front();
q.pop();
for(int i=0;i<h.s.size();i++)
{
for(int j=0;j<h.s.size();j++)
{
for(int k=1;k<=l;k++)
{
if(h.s.substr(i,j-i+1)==s1[k])
{
string x=h.s.substr(0,i)+s2[k]+h.s.substr(j+1,h.s.size()-1-j+1);
if(x.size()>20) break;
q.push({x,h.step+1});
if(h.step+1>10) return ;
if(x==b)
{
cout<<h.step+1;
exit(0);
}
}
}
}
}
}
}
signed main()
{
cin>>a>>b;
l1=a.size();
l2=b.size();
while(cin>>s1[l]>>s2[l])
{
++l;
}
l--;
bfs();
cout<<"NO ANSWER!";
return 0;
}
题