#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
//unordered_map 字符串哈希优化
const int N=6;
string a[N],b[N];
string A,B;
int n;
int extend(queue<string>& q, unordered_map<string, int>&da, unordered_map<string, int>& db,
string a[N], string b[N])
{
int d = da[q.front()];
while (q.size() && da[q.front()] == d)
{
auto t = q.front();
q.pop();
for (int i = 0; i < n; i ++ )
for (int j = 0; j < t.size(); j ++ )
if (t.substr(j, a[i].size()) == a[i])
{
string r = t.substr(0, j) + b[i] + t.substr(j + a[i].size());
if (db.count(r)) return da[t] + db[r] + 1;
if (da.count(r)) continue;
da[r] = da[t] + 1;
q.push(r);
}
}
return 11;
}
int bfs(string A,string B){
//建立两个方向的队列
queue<string> qa,qb;
unordered_map<string,int> da,db;
qa.push(A),da[A]=0;
qb.push(B),db[B]=0;
while (qa.size()&&qb.size()){
int t;
if (qa.size()<=qb.size()){
t=extend(qa,da,db,a,b);
}else{
t=extend(qb,db,da,b,a);
}
if (t<=10){
return t;
}
}
return 11;
}
int main(){
cin>>A>>B;
if (A==B){
cout<<0<<endl;
return 0;
}
while (cin>>a[n]>>b[n]) n++;//女少口阿
int step=bfs(A,B);
if (step>10){
cout<<"NO ANSWER!"<<endl;
}else{
cout<<step<<endl;
}
return 0;
}