#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){
    int n, m, st, en;
    cin >> n >> m >> st >> en;
    if(!n)
        return false;
    struct Edge{
        int from, to;
        string str;
        Edge(int from, int to, string str) : from(from), to(to), str(str){}
    };
    vector<Edge> edge_list;
    for(int i = 0; i < m; ++i){
        int from;
        int to;
        string s;
        cin >> from >> to >> s;
        edge_list.emplace_back(from, to, s);
    }

    vector<string> dp(n, "{");
    dp[en] = "";

    for(int _ = 0; _ < max(n, m) * 2; ++_){
        for(auto& edge : edge_list){
            if(dp[edge.to] == "{")
                continue;
            chmin(dp[edge.from], edge.str + dp[edge.to]);
        }
    }
    bool fl = false;
    for(int _ = 0; _ < max(n, m) * 2 && !fl; ++_){
        for(auto& edge : edge_list){
            if(dp[edge.to] == "{")
                continue;
            if(chmin(dp[edge.from], edge.str + dp[edge.to])){
                if(edge.from == st){
                    fl = true;
                    break;
                }
            }
        }
    }

    if(fl || dp[st] == "{"){
        cout << "NO" << endl;
    }
    else{
        cout << dp[st] << endl;
    }
    return true;
}

signed main(){
    while(solve());
}

