import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    while(true) {
        long n, a, s, g;
        readlnTo(n, a, s, g);
        if(n == 0) {
            return;
        }
        Tuple!(long, long ,string)[] e;
        foreach(i; iota(a)) {
            long x, y;
            string lab;
            readlnTo(x, y, lab);
            e ~= tuple(x, y, lab);
        }
        auto dp = new string[][](n,300);
        foreach(i; iota(n)) {
            foreach(j; iota(dp[i].length)) {
                dp[i][j] = null;
            }
        }
        dp[s][0] = "";
        bool update() {
            bool f = false;;
            foreach(ei; e) {
                auto x = ei[0];
                auto y = ei[1];
                auto lab = ei[2];
                foreach(i; iota(lab.length, dp[y].length)) {
                    if(dp[x][i-lab.length] is null) {
                        continue;
                    }
                    auto newLab = dp[x][i-lab.length] ~ lab;
                    if(dp[y][i] is null || newLab < dp[y][i]) {
                        dp[y][i] = newLab;
                        f = true;
                    }
                }
            }
            return f;
        }
        while(update()) {}
        string ans = null;
        foreach(dpgi; dp[g]) {
            if(dpgi !is null) {
                if(ans is null || dpgi < ans) {
                    ans = dpgi;
                }
            }
        }
        if(ans is null || ans.length > 6*n) {
            writeln("NO");
        } else {
            writeln(ans);
        }
    }
}