#include<bits/stdc++.h>
using namespace std;
struct node{
int step;
string s;
node(int step1,string s1){
step=step1;
s=s1;
}
};
string s[25][10],a,b;
int z=0;
map<string,bool> m;
void bfs(string a,string b){
queue<node> q;
q.push(node(0,a));
while (!q.empty()){
node now=q.front();
q.pop();
if (now.s==b){
cout<<now.step;
exit(0);
}
for (int i=0;i<z;i++){
string qaq=now.s;
while (114514){
if (qaq.find(s[i][0])<10000) {
qaq.replace(qaq.find(s[i][0]),(int)s[i][0].size(),s[i][1]);
if (now.step<10 && !m[qaq]) q.push(node(now.step+1,qaq));
qaq[qaq.find(s[i][0])]='%';
m[qaq]=1;
}else{
break;
}
}
}
}
cout<<"NO ANSWER!";
exit(0);
}
int main()
{
cin>>a>>b;
while (cin>>s[z][0]>>s[z][1]) {
z++;
}
bfs(a,b);
}