#include <iostream>
#include <string>
#include <queue>
using namespace std;
const int N = 15;
struct node
{
string str;
int plies;
};
string a, b;
string t1[N], t2[N];
int cnt = 1;
queue <string> q;
queue <int> p;
int ans = 0x7fffffff;
int main()
{
cin >> a >> b;
while (cin >> t1[cnt] >> t2[cnt])
{
cnt++;
}
q.push(a);
p.push(0);
while (!q.empty() && !p.empty())
{
string tmp = q.front();
int tp = p.front();
if (tmp == b || tp > 10)
{
ans = tp;
//q.pop();
//p.pop();
break;
//continue;
}
for (int i = 1; i < cnt; i++)
{
string m = tmp;
int pos = 0;
while (m.find(t1[i], pos) != m.npos)
{
pos = m.find(t1[i], pos);
m = m.replace(pos, t1[i].size(), t2[i]);
q.push(m);
p.push(tp + 1);
pos++;
m = tmp;
}
}
q.pop();
p.pop();
}
if (ans >= 0 && ans <= 10)
{
cout << ans;
}
else
{
cout << "NO ANSWER!";
}
return 0;
//p:
}
rt