require 'set'

class UnionFind
	def initialize
		@obj_to_node = {}
	end

	def add(obj)
		@obj_to_node[obj] ||= Node.new(obj)
	end

	def size(x = nil)
		x ? @obj_to_node[x].root.size : @obj_to_node.size
	end

	class Node
		def initialize(obj)
			@obj = obj
			@parent = self
			@size = 1
			@rank = 0
		end

		def root
			return self if @parent == self
			@parent = @parent.root
		end	

		attr_accessor :parent, :size, :rank
	end

	def union(x, y)
		u = (@obj_to_node[x] ||= Node.new(x)).root
		v = (@obj_to_node[y] ||= Node.new(y)).root
		return if u == v
		if u.rank > v.rank
			v.parent = u
			u.size += v.size
		elsif v.rank > u.rank
			u.parent = v
			v.size += u.size
		else
			u.parent = v
			v.rank += 1
			v.size += u.size
		end
	end

	def same?(x, y)
		return false unless u = @obj_to_node[x]
		return false unless v = @obj_to_node[y]
		u.root == v.root
	end

	def root(x)
		(@obj_to_node[x] ||= Node.new(x)).root
	end
end

loop do
	n, p1, p2 = gets.split.map &:to_i
	break if n == 0
	m = p1 + p2

	yes = []
	no = []
	n.times do
		a, b, yes_no = gets.chomp.split
		pair = [a.to_i, b.to_i]
		(yes_no == "yes" ? yes : no) << pair
	end

	if p1 == 0
		puts "end"
		next
	end

	if p2 == 0
		(1..m).each {|i| puts i}
		puts "end"
		next
	end

	if p1 == p2
		puts "no"
		next
	end
	
	uf = UnionFind.new	
	yes.each do |a, b|
		uf.union(a, b)
	end

	neighbour = (0..m).map { [] }
	no.each do |a, b|
		neighbour[b].each{|c| uf.union(a, c) }
		neighbour[a].each{|c| uf.union(b, c) }
	end
	
	roots = (0..m).map{|i| uf.root(i)} 

	pairs = []
	in_pair = []
	no.each do |a, b|
		next if a == b
		u = roots[a]
		v = roots[b]
		next if in_pair.include?(u)
		in_pair << u
		in_pair << v
		pairs << [u, v]
	end

	roots.shift

	pairs
	(roots.compact.uniq - in_pair).each{|r| pairs << [r, nil]}

	hash = {0 => []}
	pairs.each do |u, v|
		new_hash = {}		
		hash.each do |k, cs|
			l = k + u.size
			new_hash[l] = (new_hash[l] ? [nil] : cs + [u])
			if v
				l = k + v.size
				new_hash[l] = (new_hash[l] ? [nil] : cs + [v])
			else
				l = k
				new_hash[l] = (new_hash[l] ? [nil] : cs)
			end
		end
		hash = new_hash
	end
	
	if !hash[p1] || hash[p1].include?(nil)
		puts 'no'
	else
		nodes = {}
		(1..m).each do |i|
			(nodes[uf.root(i)] ||= []) << i
		end
		puts hash[p1].map{|r| nodes[r]}.flatten.sort
		puts 'end'
	end
end