#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, s, g, a, b; string t;
int main() {
	while (cin >> n >> m >> s >> g, n) {
		vector<vector<pair<int, string> > > G(n);
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> t;
			G[a].push_back(make_pair(b, t));
		}
		vector<vector<string> > dp(n * 12 + 1, vector<string>(n, "~"));
		dp[0][s] = "";
		for (int i = 0; i < n * 12; i++) {
			for (int j = 0; j < n; j++) {
				if (dp[i][j] == "~") continue;
				for (pair<int, string> k : G[j]) {
					int l = i + k.second.size();
					if (l <= n * 12) dp[l][k.first] = min(dp[l][k.first], dp[i][j] + k.second);
				}
			}
		}
		int p = -1; string ret = "~";
		for (int i = 0; i <= n * 12; i++) {
			if (ret > dp[i][g]) ret = dp[i][g], p = i;
		}
		if (p > n * 6 || p == -1) cout << "NO" << endl;
		else cout << ret << endl;
	}
	return 0;
}