#include <cstdio>
#include <set>
#include <vector>
#include <iostream>

using namespace std;
string s, t;

set <string> T;

struct data
{
	string t, s;
} a [10];

int n, d [100000], step;
string str;
vector <string> q;

bool ck (string s, int tp)
{
	string hehe = "";
	for (int now = 0; now < (int) s.length (); )
	{
		if (s.substr (now, a[tp].t.length ()) == a[tp].t)
		{
			hehe += a[tp].s;
			now += (int) a[tp].t.length ();
		}
		else
		{
			hehe += s[now];
			++now;
		}
	}
	return str == hehe;
}

bool dfs (string ts, int tp, int now)
{
	if (now == (int) str.length ())
	{
		if (T.find (ts) == T.end () && ck (ts, tp))
		{
			T.insert (ts);
			d[q.size ()] = step + 1;
			q.push_back (ts);
			if (ts == t)
				return 1;
		}
		return 0;
	}
	bool flag = 0;
	if (str.substr (now, a[tp].s.length ()) == a[tp].s)
		flag |= dfs (ts + a[tp].t, tp, now + (int) a[tp].s.length ());
	flag |= dfs (ts + str[now], tp, now + 1); 
	return flag;
}

void bfs ()
{
	T.clear ();
	T.insert (s);
	q.clear ();
	q.push_back (s);
	string x = s;
	d[0] = 0;
	for (int head = 0; head < (int) q.size (); x = q[++head])
	{
		str = x;
		step = d[head];
		for (int i = 0; i < n; ++i)
			if (x.find (a[i].s) != string:: npos)
			{
				if (dfs ("", i, 0))
				{
					cout << step + 1 << endl;
					return ;
				};
			}
		if (head == (int) q.size () - 1) break;
	}
	cout << -1 << endl;
}

int main ()
{
	while (1)
	{
		cin >> n;
		if (n == 0) break;
		T.clear ();
		for (int i = 0; i < n; ++i) cin >> a[i].t >> a[i].s;
		cin >> t;
		cin >> s;
		bfs ();
	}
	return 0;
}