#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct node{
    int index,length;
	string cost;
    node(int index,int length,string cost):index(index),length(length),cost(cost){}
    bool operator<(const node& other)const{
        return cost>other.cost;
    }
};
const int MAX_LEN=500;

const string MAX(2*MAX_LEN,'z');
const string NONE="-";
const string MIN="";

typedef vector<vs> vvs;
int main(){
    int n,a,s,g;
    while(cin>>n>>a>>s>>g,n){
        vector<vvs> dist(n,vvs(n,vs()));
        REP(i,a){
            int x,y;
			string lab;
            cin>>x>>y>>lab;
			dist[x][y].push_back(lab);
        }
        
        priority_queue<node> q;
        q.push(node(s,0,MIN));
        vvs cost(n,vs(MAX_LEN+6+1,MAX));
        cost[s][0]=MIN;
        while(!q.empty()){
            node cnode=q.top();q.pop();
            if(cost[cnode.index][cnode.length]<cnode.cost){
                continue;
            }
            REP(i,n){
				REP(j,dist[cnode.index][i].size()){
					if(dist[cnode.index][i][j]!=NONE){
						string newcost=cnode.cost+dist[cnode.index][i][j];
						if(newcost.size()<=MAX_LEN+6&&cost[i][newcost.size()]>newcost){
							cost[i][newcost.size()]=newcost;
							q.push(node(i,newcost.size(),newcost));
						}
					}
				}
            }
        }
		string ans=MAX;
		REP(i,MAX_LEN+6+1){
			ans=min(ans,cost[g][i]);
		}
		if(ans.length()>n*6){
			cout<<"NO"<<endl;
		}else{
			cout<<ans<<endl;
		}
    }
}