import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int N;
    string[] A, B;
    string S, T;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        A = new string[N];
        B = new string[N];
        foreach (i; 0 .. N) {
            auto _ = readln.chomp.split(" ").array;
            A[i] = _[0];
            B[i] = _[1];
        }
        S = readln.chomp;
        T = readln.chomp;
        return true;
    }
    struct P {
        string s;
        int t;
    }
    void solve() {
        DList!P Q;
        Q.insert(P(S, 0));
        int Ans = -1;
        while (!Q.empty) {
            P p = Q.front; Q.removeFront;
            if (p.s == T) {
                Ans = p.t;
                break;
            }
            foreach (i; 0 .. N) {
                string ns = p.s.replace(A[i], B[i]);
                if (ns.length > 10) continue;
                Q.insert(P(ns, p.t + 1));
            }
        }
        writeln(Ans);
    }
    while (input) solve;
}