#include <iostream>
#include <queue>
using namespace std;
typedef pair<string,int> psi;
#define repeat(i,n) for (int i = 0; i < (n); ++i)
#define MAX_N 10
string substitute(const string & s, const string & a, const string & b) {
    string dest;
    int i = 0;
    while (i < (int)s.length() - (int)a.length() + 1) {
        if (s.substr(i,a.length()) == a) {
            dest += b;
            i += a.length();
        } else {
            dest += s[i];
            ++ i;
        }
    }
    while (i < (int)s.length()) {
        dest += s[i];
        ++ i;
    }
    return dest;
}
int N;
string a[MAX_N], b[MAX_N], g, d;
bool input() {
    cin >> N;
    if (N == 0) return false;
    repeat (i,N) cin >> a[i] >> b[i];
    cin >> g >> d;
    return true;
}
int solve() {
    queue<psi> q;
    q.push(psi(g,0));
    while (not q.empty()) {
        string s = q.front().first;
        int    m = q.front().second;
        q.pop();
        repeat (i,N) {
            string t = substitute(s, a[i], b[i]);
            if (t != s) {
                if (t == d) {
                    return m+1;
                } else if (t.length() < d.length()) {
                    q.push(psi(t,m+1));
                }
            }
        }
    }
    return -1;
}
int main() {
    while (input()) cout << solve() << endl;
    return 0;
}