#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1001;
struct st
{
string x;
int step;
} q[100005];
int cnt=0,step,fron,rear;
string n,m,a[maxn],b[maxn];
map<string,bool>vis;
int bfs()
{
st now;
now.x=n;
now.step=0;
fron=rear=0;
q[rear]=now;
rear++;
while(fron<rear)
{
now=q[fron++];
if(now.x==m)
{
printf("%d\n",now.step);
return 0;
}
if(now.step>10)
{
return -1;
}
for(int i=0; i<cnt; i++)
{
string temp=now.x;
int pos=temp.find(a[i]);
while(pos!=-1)
{
temp.replace(pos,a[i].length(),b[i]);
if(vis[temp]==0)
{
vis[temp]=true;
q[rear].x=temp;
q[rear].step=now.step+1;
rear++;
}
temp=now.x;
pos=temp.find(a[i],pos+1);
}
}
}
return -1;
}
int main()
{
cin>>n>>m;
cnt=0;
while(cin>>a[cnt]>>b[cnt])
cnt++;
if(bfs()<0)
{
printf("NO ANSWER!\n");
}
return 0;
}