loop do
  n, m, s, g = gets.split.map(&:to_i)
  break if n == 0
  graph = {}
  (0..n-1).each {|i| graph[i] = [] }
  m.times do
    i, j, l = gets.split
    graph[i.to_i] << [j.to_i, l]
  end

  # Reverse Bellman-Ford
  best_suffix = { g => "" }
  rbf = proc do
    new_suffix = best_suffix.dup
    (0..n-1).each do |i|
      graph[i].each do |j, l|
        next if !best_suffix[j]
        new_suffix[i] = [ new_suffix[i] || ?{, l + best_suffix[j] ].min
      end
    end
    best_suffix = new_suffix
  end

  (7 * n).times { rbf.call }
  if best_suffix[s] && best_suffix[s].size < 6 * n
    puts best_suffix[s]
  else
    puts 'NO'
  end
end
