#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <limits>

using namespace std;

using lint = long long;

constexpr int INF = numeric_limits<int>::max() / 2;

string sed(string a, string b, string s) {
    string ret;
    for (int i = 0; i < s.length();) {
        bool judge = true;
        for (int j = 0; j < a.length(); ++j) {
            if (i + j >= s.length() || a[j] != s[i + j]) {
                judge = false;
                break;
            }
        }
        if (judge) {
            ret += b;
            i += a.length();
        } else {
            ret.push_back(s[i]);
            ++i;
        }
    }

    return ret;
}

bool solve() {
    int n;
    cin >> n;
    if (n == 0) return false;

    vector<pair<string, string>> ps(n);
    for (auto& p : ps) cin >> p.first >> p.second;
    string s, g;
    cin >> s >> g;

    function<int(string)> dfs =
        [&](string ss) {
            int ret = INF;
            if (ss == g) {
                ret = 0;
            } else if (ss.length() < g.length()) {
                for (auto p : ps) {
                    string gg = sed(p.first, p.second, ss);
                    if (ss != gg) ret = min(ret, dfs(gg) + 1);
                }
            }
            return ret;
        };

    int ans = dfs(s);
    cout << (ans == INF ? -1 : ans) << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}

