#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <sstream>

using namespace std;

string substitute(string const& s, string const& from, string const& to) {
	stringstream result;
	size_t i = 0;
	while (true) {
		auto found = s.find(from, i);
		if (found == string::npos) {
			for (; i < s.size(); i++) {
				result << s[i];
			}
			break;
		}
		else {
			for (; i < found; i++) {
				result << s[i];
			}
			result << to;
			i += from.size();
		}
	}

	return result.str();
}

void solve(int n) {
	vector<string> from(n, "");
	vector<string> to(n, "");

	for (int i = 0; i < n; i++) {
		cin >> from[i] >> to[i];
	}
	string start;
	string end;
	cin >> start;
	cin >> end;

	queue<pair<size_t, string>> replaced;
	replaced.push(make_pair(0, start));

	while (!replaced.empty()) {
		auto top = replaced.front();
		replaced.pop();

		if (top.second == end) {
			cout << top.first << endl;
			return;
		}

		for (int i = 0; i < n; i++) {
			auto next = substitute(top.second, from[i], to[i]);
			if (next.size() <= end.size() && top.second != next) {
				replaced.push(make_pair(top.first + 1, next));
			}
		}
	}
	cout << -1 << endl;
}

int main() {
	int n;
	while (cin >> n && n) {
		solve(n);
	}
}