#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps=1e-8;
string trans(string base, string keyfr,string keyto) {
	string res;
	int len = base.length();
	int lon = keyfr.length();
	rep(i, len) {
		if (i + lon <= len) {
			string chk = base.substr(i, lon);
			if (chk == keyfr) {
				res += keyto; i += lon - 1;
			}
			else {
				res += base[i];
			}
		}
		else {
			res += base[i];
		}
	}
	return res;
}
int main() {
	int n;
	while (cin >> n, n) {
		map<string, int>used;
		pair<string,string> x[10];
		rep(i, n) {
			string a, b; cin >> a >> b; x[i] = { a,b };
		}
		string sta, las;
		cin >> sta >> las;
		queue<string> q;
		q.push(sta); used[sta] = 1;
		int cnt = 0; bool f = false;
		while (!q.empty()) {
			int len = q.size();
			rep(nexxxxxxxxt, len) {
				string now = q.front(); q.pop();
				if (now == las) {
					f = true; break;
				}
				rep(i, n) {
					string nex = trans(now, x[i].first, x[i].second);
					if (nex.length()<=10&&used[nex] != 1) {
						used[nex] = 1;
						q.push(nex);
					}
				}
			}
			if (f)break;
			cnt++;
		}
		if (f) {
			cout << cnt << endl;
		}
		else {
			cout << -1 << endl;
		}
	}
	return 0;
}
