#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

string replace(string &a,string &b,string &c){
	string ret;
	int p=0,q;
	for(;(q=a.find(b,p))!=a.npos;){
		ret+=a.substr(p,q-p)+c;
		p=q+b.size();
	}
	return ret+a.substr(p);
}
int main()
{
	int n;
	string a[10],b[10];
	string g,d;
	while(cin>>n,n){
		rep(i,n)cin>>a[i]>>b[i];
		cin>>g>>d;
		set<string> v;
		queue<pair<int,string> > q;
		q.push(mp(0,g));
		while(!q.empty()){
			string c=q.front().second; int cc=q.front().first; q.pop();
			if(v.count(c))continue;
			v.insert(c);
			if(c==d){
				cout<<cc<<endl;
				goto END;
			}
			rep(i,n){
				string nx=replace(c,a[i],b[i]);
				if(nx.size()<=d.size())q.push(mp(cc+1,nx));
			}
		}
		cout<<-1<<endl; END:;
	}
	return 0;
}