#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int from, to;
    string lab;
    Edge(int from0, int to0, string& lab0){
        from = from0;
        to = to0;
        lab = lab0;
    }
};

string solve(int n, vector<Edge>& edges, int s, int g)
{
    int m = edges.size();
    string INF = string(1, 'z' + 1);
    vector<string> powerful(n, INF);
    powerful[g] = "";

    string prev = INF;
    for(int i=0; i<6*n; ++i){
        bool change = false;
        for(int j=0; j<m; ++j){
            int from = edges[j].from;
            int to = edges[j].to;
            string& lab = edges[j].lab;
            if(powerful[to] == INF)
                continue;
            string s = lab + powerful[to];
            if(s < powerful[from]){
                powerful[from] = s;
                change = true;
            }
        }
        if(prev != powerful[s]){
            if(i >= n - 1)
                return "NO";
            prev = powerful[s];
        }
    }
    if(powerful[s] == INF)
        return "NO";
    else    
        return powerful[s];
}

int main()
{
    int n, a, s, g;
    for(;;){
        cin >> n >> a >> s >> g;
        if(n == 0)
            break;
        vector<Edge> edges;
        for(int i=0; i<a; ++i){
            int x, y;
            string lab;
            cin >> x >> y >> lab;
            edges.push_back(Edge(x, y, lab));
        }
        cout << solve(n, edges, s, g) << endl;
    }
}