#include<iostream>
#include<set>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
string edge[10][2];

string substitute(string tar,string from,string to){
  string ret;
  for(int i=0;i<tar.size();i++){
    bool flag=true;
    rep(j,from.size()){
      if ( from[j]!=tar[i+j]){flag=false;break;}
    }
    if ( flag == false)ret+=tar[i];
    else {
      ret+=to;
      i+=from.size()-1;
    }
  }
  return ret;
}

int bfs(string start,string goal,int n){
  queue<pair<string,int> > Q;
  set<string>S;
  Q.push(make_pair(start,0));
  S.insert(start);
  while(!Q.empty()){
    pair<string,int> now =Q.front();
    Q.pop();
    if ( now.first == goal)return now.second;
    rep(i,n){
      string next = substitute(now.first,edge[i][0],edge[i][1]);
      if ( S.find(next) == S.end() && next.size()<= goal.size()){
	S.insert(next);
	Q.push(make_pair(next,now.second+1));
      }
    }
    
  }
  return -1;
}


int main(){

  int n;
  while(cin>>n && n){
    string start,goal;
    rep(i,n)cin>>edge[i][0]>>edge[i][1];
    cin>>start>>goal;
    cout << bfs(start,goal,n) <<endl;
  }
}