import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.container;
import std.array;
import std.math;
import std.range;
import std.typecons;
import core.stdc.stdio : getchar;
import std.ascii;

// pragma(msg, min("a", "aa"));
// pragma(msg, min("~", "aa"));

void main()
{
  for (;;)
  {
    int n, a, s, g;
    n = next(a => isDigit(a)).to!int;
    a = next(a => isDigit(a)).to!int;
    s = next(a => isDigit(a)).to!int;
    g = next(a => isDigit(a)).to!int;
    if (!(n | a | s | g))
    {
      break;
    }
    alias Node = Tuple!(string, "lab", int, "dist");
    alias Adj = SList!Node;
    Adj[] adjs = new Adj[](n);
    for (int _ = 0; _ < a; ++_)
    {
      int x, y;
      string lab;
      // {
      //   auto i = readln.chomp.split;
      //   x = i[0].to!int;
      //   y = i[1].to!int;
      //   lab = i[2];
      // }
      x = next(a => isDigit(a)).to!int;
      y = next(a => isDigit(a)).to!int;
      lab = next(a => isAlpha(a));
      // stderr.writeln(_, " : ", x, " ", y, " ", lab, " ... ", n, ", ", a);
      adjs[x].insert(Node(lab, y));
    }
    Node atom = Node("", s);
    string ans = "~";
    string loop = "~";
    BinaryHeap!(Node[], "a > b") queue = BinaryHeap!(Node[], "a > b")([]);
    queue.insert(atom);
    bool[] done = new bool[](n);
    while (queue.length)
    {
      Node node = queue.front;
      queue.popFront;
      if (node.dist == g)
      {
        ans = min(ans, node.lab);
      }
      // stderr.writeln("!!!!", node.dist, "/", n);
      if (done[node.dist])
      {
        loop = min(loop, node.lab);
        continue;
      }
      done[node.dist] = true;
      foreach (adj; adjs[node.dist])
      {
        Node next = Node(node.lab ~ adj.lab, adj.dist);
        queue.insert(next);
      }
    }
    if (done[g] && ans <= loop)
    {
      writeln = ans;
    }
    else
    {
      writeln = "NO";
    }
  }
}

string next(bool function(dchar) func)
{
  static char tmp;
  string str;
  if (func(tmp))
  {
    str ~= tmp;
  }
  else
  {
    for (;;)
    {
      char c = cast(char) getchar();
      if (func(c))
      {
        str ~= c;
        break;
      }
    }
  }
  for (;;)
  {
    char c = cast(char) getchar();
    if (!func(c))
    {
      tmp = c;
      break;
    }
    str ~= c;
  }
  return str;
}