#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;
typedef pair<int, int> PI;

const ll inf = 1e15;
const ll mod = 1000 * 1000 * 1000 + 7;
const double eps = 1e-9;

template <typename S, typename T> ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}


int main(){
  int n, a, s, g;
  while (cin >> n >> a >> s >> g && n){
    vector<int> F(a), T(a);
    vector<string> S(a);
    REP(i, a) cin >> F[i] >> T[i] >> S[i];
    vector<string> D(n, string(1, 'z' + 1));
    D[g] = "";

    bool ng = false;
    REP(i, 10 * n + 1){
      REP(j, a){
        if (D[T[j]][0] != 'z' + 1 && D[F[j]] > S[j] + D[T[j]]){
          D[F[j]] = S[j] + D[T[j]];
          if (i >= n && F[j] == s) ng = true;
        }
      }
    }
    // cout << D[s] << endl;
    cout << (ng || D[s][0] == 'z' + 1 ? "NO" : D[s]) << endl;
  }
  return 0;
}