#include <bits/stdc++.h>
using namespace std;

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000
typedef long long LL;
typedef long double LD;

class Solver{
private:
  int n;
  vector<string> a,b;
  map<string,int> mp;
public:
  Solver(int nn){
    n=nn;
    a=vector<string>(n);
    b=vector<string>(n);
    for(int i=0;i<n;i++){
      cin >> a[i] >> b[i];
    }
  }
  int solve(string s,string t){
    if(s==t) return 0;
    string tmp;
    int mi=INF;
    for(int i=0;i<n;i++){
      if(s.length()<a[i].length()) continue;
      tmp=s;
      for(int j=0;j<=tmp.length()-a[i].length();j++){
        if(tmp.substr(j,a[i].length())==a[i]){
          tmp=tmp.substr(0,j)+b[i]+tmp.substr(j+a[i].length(),tmp.length()-(j+a[i].length()));
          j+=b[i].length()-1;
        }
      }
      if(tmp!=s&&tmp.length()<=t.length()){
        if(mp.find(tmp)==mp.end()){
          int x=solve(tmp,t);
          mp[tmp]=x;
          mi=min(mi,x);
        }else{
          mi=min(mi,mp[tmp]);
        }
      }
    }
    return min(mi+1,INF);
  }
};

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    Solver s(n);
    string c,d;
    cin >> c >> d;
    int ans=s.solve(c,d);
    cout << (ans==INF?-1:ans) << endl;
  }
  return 0;
}

