#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int n;
vector<string> a(10);
vector<string> b(10);
string g, d;

queue<string> que;

string repl(string s, int i) {
    string s2 = s.substr(a[i].size());
    int x = s2.find(a[i]);
    if (x != string::npos) {
        string s3 = s2.substr(0,x) + repl(s2.substr(x), i);
        return b[i] + s3;
    }
    else return b[i] + s2;
}

int bfs(int c) {
    if (c > 8) return -1;
    queue<string> que2;
    while (!que.empty()) {
        string s = que.front();
        que.pop();
        for (int i = 0; i < n; i++) {
            int x = s.find(a[i]);
            if (x == string::npos) continue;
            string s2 = s.substr(x);
            string s3 = s.substr(0, x) + repl(s2,i);
            if (s3 == d) return c+1;
            que2.push(s3);
        }
    }
    que = que2;
    return bfs(c+1);
}

int main(void){
    while (cin>>n && n) {
        for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
        cin >> g >> d;
        queue<string> a;
        que = a;
        que.push(g);
        cout << bfs(0) << endl;
    }
}