#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef pair<int, string> NODE;
typedef queue<NODE> QUEUE;
typedef set <string> SET;
const int SIZE = 11;

int n;
string A[SIZE];
string B[SIZE];

string ReplaceAll(string str, const string& from, const string& to)
{
    string::size_type pos = 0;
    while(pos = str.find(from, pos), pos != string::npos) {
        str.replace(pos, from.length( ), to);
        pos += to.length();
    }
    return str;
}

int solve( string a, string b ) {
    SET v;
    v.insert( a );
    NODE start( 0, a );
    QUEUE q;
    q.push( start );
    while ( ! q.empty() ) {
        NODE node = q.front();
        q.pop();

        int c = node.first;
        string s = node.second;

        if ( s == b ) {
            return c;
        }
            
        for ( int i = 0; i < n; ++ i ) {
            string ns = ReplaceAll( s, A[i], B[i] );
            int nc = c + 1;
            if ( ns.size() > b.size() ) continue;
            if ( v.count( ns ) ) continue;
            v.insert( ns );
            NODE next( nc, ns );
            q.push( next );
        }
    }
    return -1;
}

int main() {
    while ( cin >> n && n ) {
        for ( int i = 0; i < n; ++ i ) {
            cin >> A[i] >> B[i];
        }
        
        string a, b;
        cin >> a >> b;
        cout << solve( a, b ) << endl;
    }
    return 0;
}