#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

string sed(const string& s, const string& pattern1, const string& pattern2) {
    string t = "";
    for (int j = 0, k = 0;; j = k + pattern1.size()) {
        k = s.find(pattern1, j);
        if (k == string::npos) {
            t += s.substr(j);
            break;
        }
        t += s.substr(j, k - j) + pattern2;
    }
    return t;
}

int solve(int n,
          const vector<string>& alpha, const vector<string>& beta,
          const string& gamma, const string& delta) {
    map<string, int> mem; mem[gamma] = 0;
    priority_queue<pair<int, string>> Q;
    for (Q.emplace(0, gamma); !Q.empty();) {
        int c; string s; tie(c, s) = Q.top(); Q.pop();
        if (s == delta) return -c;
        if (mem[s] != c) continue;
        rep(i, n) {
            string t = sed(s, alpha[i], beta[i]);
            if (t == s || t.size() > delta.size()) continue;
            if (!mem.count(t) || mem[t] < c - 1) Q.emplace(mem[t] = c - 1, t);
        }
    }
    return -1;
}

int main() {
    for (int n; cin >> n, n;) {
        vector<string> alpha(n), beta(n);
        rep(i, n) cin >> alpha[i] >> beta[i];
        string gamma, delta; cin >> gamma >> delta;
        cout << solve(n, alpha, beta, gamma, delta) << endl;
    }
}