#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
string dp[40][500]; int n, m, s, g;
vector<pair<int, string>>x[40];
bool solve() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 480; j++)dp[i][j] = "~";
	}
	dp[s][0] = "";
	for (int j = 0; j < 480; j++) {
		for (int i = 0; i < n; i++) {
			if (dp[i][j] == "~")continue;
			for (int k = 0; k < x[i].size(); k++) {
				int a1 = x[i][k].first, a2 = x[i][k].second.size();
				dp[a1][j + a2] = min(dp[a1][j + a2], dp[i][j] + x[i][k].second);
			}
		}
	}
	string minx = "~"; int minid = -1;
	for (int i = 0; i < 480; i++) {
		if (dp[g][i] < minx) { minx = dp[g][i]; minid = i; }
	}
	if (minid >= 350 || minid == 0 || minid == -1) { cout << "NO" << endl; return false; }
	cout << minx << endl;
	return true;
}
int main() {
	while (true) {
		cin >> n >> m >> s >> g; if (n == 0)break;
		for (int i = 0; i < n; i++) { x[i].clear(); }
		for (int i = 0; i < m; i++) {
			int a, b; string T; cin >> a >> b >> T;
			x[a].push_back(make_pair(b, T));
		}
		solve();
	}
	return 0;
}