#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
string a[10],b[10],s,t;
map<string,int> d;
string nst(string x,string a,string b){
	string nx;
	int L=x.size();
	int M=a.size();
	rep(j,L){
		if(j<L-M+1&&x.substr(j,M)==a){
			nx+=b;
			j+=M-1;
		}else{
			nx+=x[j];
		}
	}
	return nx;
}
int main(){
	while(true){
		int N;
		cin>>N;
		if(N==0) break;
		rep(i,N) cin>>a[i]>>b[i];
		cin>>s>>t;
		queue<string> que;
		d.clear();
		d[s]=0;
		que.push(s);
		while(!que.empty()){
			string x=que.front();
			que.pop();
			rep(i,N){
				string nx=nst(x,a[i],b[i]);
				if(x==nx||nx.size()>t.size()) continue;
				if(!d.count(nx)||d[nx]>d[x]+1){
					d[nx]=d[x]+1;
					que.push(nx);
				}
			}
		}
		if(d.count(t)) cout<<d[t]<<endl;
		else puts("-1");
	}
}