import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

string INF = "|";
void main() {
    string[] input;
    while(true) {
        input = readln.split;
        if (input == ["0", "0", "0", "0"]) break;

        int n = input[0].to!int;
        int a = input[1].to!int;
        int s = input[2].to!int;
        int g = input[3].to!int;

        string[] vertices = new string[n];
        vertices[] = INF;
        Edge[] edges = new Edge[a];
        foreach(int i; 0..a) {
            input = readln.split;
            edges[i] = Edge(input[1].to!int, input[0].to!int, input[2]);
        }

        vertices[g] = "";
        bool flg = false;
        for (int count=0; count<vertices.length; count++) {
            for (int i=0; i<edges.length; i++) {
                string value = edges[i].cost~vertices[edges[i].from];
                if (value < vertices[edges[i].to]) {
                    vertices[edges[i].to] = value;
                    if (count == vertices.length-1) {
                        flg = true;
                    }
                }
            }
        }
        writeln(vertices[s] == INF || flg ? "NO":vertices[s]);
    }
}
struct Edge {
    int from, to;
    string cost;
    this(int from, int to, string cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }
}