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

map<string, int> mp;
int n;
vector<pair<string, string>> p;
string st, go;

int solve();
string make(string s, int x);

int main() {
  while(1) {
    cin >> n;
    if(n == 0) break;
    for(int i = 0; i < n; ++i) {
      string s, t;
      cin >> s >> t;
      p.push_back(make_pair(s, t));
    }
    cin >> st >> go;
    cout << solve() << endl;
    mp.erase(mp.begin(), mp.end());
    p.erase(p.begin(), p.end());
  }
  return 0;
}

int solve() {
  queue<string> qu;
  qu.push(st);
  mp[st] = 0;
  while(qu.size() > 0) {
    string now = qu.front(), nexts;
    qu.pop();
    if(now.size() >= go.size()) continue;
    for(int i = 0; i < n; ++i) {
      nexts = make(now, i);
      if(mp.find(nexts) == mp.end()) {
        mp[nexts] = mp[now] + 1;
        qu.push(nexts);
      }
      if(nexts == go) return mp[now] + 1;
    }
  }
  return -1;
}

string make(string s, int x) {
  string nexts;
  for(int i = 0; i < s.size(); ++i) {
    int k;
    for(k = 0; k < p[x].first.size() && k + i < s.size();
        ++k)
      if(p[x].first[k] != s[k + i]) break;
    if(k == p[x].first.size()) {
      nexts += p[x].second;
      i += k - 1;
    }
    else
      nexts += s[i];
  }
  return nexts;
}
