def dfs(s, cnt):
global y, ans
if cnt == 11:
return
if s == y:
ans = min(ans, cnt)
return
for i in range(len(a)):
if a[i] in s:
dfs(s[: s.index(a[i])] + b[i] + s[s.index(a[i]) + len(a[i]) :], cnt + 1)
return
x, y = map(str, input().split())
w = input()
a = []
b = []
while w != "":
a.append(w[: w.index(" ")])
b.append(w[w.index(" ") + 1 :])
w = input()
ans = 11
dfs(x, 0)
if ans != 11:
print(ans)
else:
print("NO ANSWER!")