#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
const int N = 6;
string a[N], b[N];
int extend(queue<string> &qa, map<string, int> &ma, map<string, int> &mb, string a[], string b[])
{
string t = qa.front();
qa.pop();
for(int i = 0; i < t.size(); i++)
{
for(int j = 0; j < 6; j++)
{
if(t.substr(i, a[j].size()) == a[j])
{
string st = t.substr(0, i) + b[j] + t.substr(i + a[j].size());
if(mb.count(st)) return mb[st] + 1 + ma[t];
if(ma.count(st)) continue;
ma[st] = ma[t] + 1;
qa.push(st);
}
}
}
return 11;
}
int Bfs(string A, string B)
{
queue<string> qa, qb;
map<string, int>ma, mb;
qa.push(A);
qb.push(B);
ma[A] = 0;
mb[B] = 0;
while(qa.size() && qb.size())
{
int t = 0x3f3f3f3f;
if(qa.size() >= qb.size())
t = extend(qb, mb, ma, b, a);
else
t = extend(qa, ma, mb, a, b);
if(t <= 10) return t;
}
return 11;
}
int main()
{
string A, B;
cin >> A >> B;
for(int i = 0; i < 6; i++) cin >> a[i] >> b[i];
int t = Bfs(A, B);
if(t > 10) cout << "NO ANSWER!" << endl;
else cout << t << endl;
return 0;
}