#include <iostream>
#include <vector>
#include <queue>
using namespace std;
string a, b;
vector<string> before;
vector<string> after;
bool found = false;
int min_d = 120999;
void dfs(string cur_str, int depth) {
cerr << cur_str << " " << depth << endl;
if (cur_str == b) {
if (depth < min_d) min_d = depth;
found = true;
}
if (depth == 10) {
if (cur_str != b) return;
}
for (int i = 0; i < before.size(); ++i) {
auto f = cur_str.find(before[i]);
if (f != string::npos) {
string temp = cur_str;
temp.replace(f, before[i].size(), after[i]);
dfs(temp, depth+1);
}
}
}
int main() {
cin >> a >> b;
string temp_a, temp_b;
while (cin >> temp_a >> temp_b) {
before.push_back(temp_a);
after.push_back(temp_b);
}
dfs(a, 0);
if (!found) {
cout << "NO ANSWER!" << endl;
return 0;
}
cout << min_d << endl;
}