loop {
	n, m, start, goal = gets.split.map &:to_i
	break if n == 0
	hash = (1..n).map{ {} }
	hash[start][0] = ""

	edges = (1..m).map {
		i, j, s = gets.chomp.split
		[i.to_i, j.to_i, s]
	}

	(n-1).times {
		edges.each{|i, j, s1|
			new = hash[j].dup
			hash[i].each{|_, s2|
				s = s2 + s1
				k = s.size
				if new[k]
					new[k] = s if s < new[k]	
				else
					new[k] = s
				end
			}
			hash[j] = new
		}
	}
	min = hash[goal].values.min
	if !min
		puts 'NO'
		next
	end	
	
	puts min
}