#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<string>
#include<algorithm>

using namespace std;

#define FOR(I, A, B) for (int I = int(A); I < int(B); ++I)

const int N(11), P(27);

int ans, n;
string S, T;
string A[N], B[N];

string change(string &s, int c) {
    string ret = "";
    int x = 0;
    for (; x < s.size(); ++x) 
        if (s.substr(x, A[c].size()) == A[c]) {
            ret += B[c]; x += A[c].size() - 1;
        }
        else ret += s[x];
    return ret;
}

bool dfs(int x, string s) {
    if (s == T) return true;
    if (x >= ans || s.size() >= T.size()) return false;
    FOR(i, 0, n) {
       string ss = change(s, i);
       if (ss.size() > s.size()) {
           if (dfs(x + 1, change(s, i))) return true;
       }
    }
    return false;
}

int main() {
    while (cin >> n, n) {
        FOR(i, 0, n)
            cin >> A[i] >> B[i];
        cin >> S >> T;
        for (ans = 0; ans < 10 && !dfs(0, S); ++ans);
        if (ans == 10) printf("-1\n");
        else printf("%d\n", ans);
    }
    return 0;
}