#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<string> a(n), b(n);
    string g,d;
    REP(i,n)cin>>a[i]>>b[i];
    cin>>g>>d;
    queue<pair<int,string>> q;
    q.push(make_pair(0,g));
    int res = -1;
    while(!q.empty()) {
      int m; string s;
      tie(m,s) = q.front(); q.pop();
      if (m > d.size()) {
        break;
      } else if (s == d) {
        res = m;
        break;
      } else {
        REP(i,n) {
          string cp = s;
          int j = 0;
          while ((j = cp.find(a[i], j)) != string::npos) {
            cp.replace(j, a[i].size(), b[i]);
            j += b[i].size();
          }
          if (cp != s) q.push(make_pair(m+1, cp));
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}