#include <bits/stdc++.h>
using namespace std;

struct edge {
    int from, to;
    string w;
};

using edges = vector<edge>;

const string INF = "NO";

string solve(edges const& es, int s, int t, const int V) {
    vector<string> d(V, INF);
    d[t] = "";
    for(int i=0; i<V*7; ++i) {
        vector<string> tmp = d;
        for(auto& e : es) {
            if(tmp[e.to] != INF && (tmp[e.from] == INF || tmp[e.from] > e.w + tmp[e.to])) {
                tmp[e.from] = e.w + tmp[e.to];
                
                if(i >= V && e.from == s) {
                    return "NO";
                }
            }
        }
        d.swap(tmp);
    }
    return d[s];
}

int main() {
    int n, a, s, g;
    while(cin >> n >> a >> s >> g, n) {
        edges es(a);
        for(int i=0; i<a; ++i) {
            cin >> es[i].from >> es[i].to >> es[i].w;
        }
        cout << solve(es, s, g, n) << endl;
    }
}