#include<bits/stdc++.h>
using namespace std;
int n,h,t=1;
string a,b,ca[1001],cb[1001];
struct node {
int cnt;
string s;
} q[2000001];
main() {
cin>>a>>b;
while(cin>>ca[n]>>cb[n]) {
n++;
}
q[1].s=a,q[1].cnt=0;
while(h<t) {
if(q[h].cnt>10){
cout<<"NO ANSWER!";
return 0;
}
++h;
for(int i=0; i<n; i++) {
int id=q[h].s.find(ca[i],0);
while(1+1==2) {
if(id==-1) {
break;
} else {
++t;
q[t].cnt=q[h].cnt+1;
q[t].s=q[h].s;
q[t].s.replace(id,ca[i].size(),cb[i]);
if(q[t].s==b) {
cout<<q[t].cnt;
return 0;
}
id=q[t].s.find(ca[i],id+1);
}
}
}
}
}