require 'set'

class Graph
	def initialize
		@nodes = Set.new
		@edges = Set.new
	end

	def add_node(label = nil)
		Node.new(label)
	end

	def add_edge(u, v)
		e = Edge.new(u, v)
		u.outgoings << e
		v.incomings << e
		e
	end
	
	def del_edge(e)
		u, v = e.from, e.to
		u.outgoings.delete(e)
		v.incomings.delete(e)
		e
	end

	class Node
		def initialize(label)
			@label = label
			@outgoings = Set.new
			@incomings = Set.new
		end
		
		def to_s
			@label
		end
		attr_accessor :incomings, :outgoings
		attr_reader :label
	end

	class Edge
		def initialize(u, v)
			@from = u	
			@to = v
		end
		attr_reader :from, :to
	end

	def Graph::get_path_bfs(s, t)
		path_edge = {}
		reached = Set[s]
		queue = [s]
		while !queue.empty? 
			u = queue.shift
			u.outgoings.each{|e|
				v = e.to
				next if reached.include?(v)	
				reached << v
				queue << v
				path_edge[v] = e

				if v == t
					path = []
					while e = path_edge[v]
						path.unshift e
						v = e.from
					end
					return path
				end
			}
		end	
		return nil
	end

	def Graph::get_path_dfs(s, t, reached = Set.new)
		reached << s	
		s.outgoings.each{|e|
			v = e.to
			next if reached.include?(v)
			return [e] if v == t
			
			path = get_path_dfs(v, t, reached) 
			return [e] + path if path
		}
		nil
	end

	def make_layer_graph(s, t) #nodes:copy, edges:alias
		lg = Graph.new
		correspond = {}

		path_edge = {}
		reached = Set[s]
		current_queue = [s]

		correspond[s] = lg.add_node

		while 0
			next_queue = []
			while !current_queue.empty? 
				u = current_queue.shift
				u.outgoings.each{|e|
					v = e.to
					next if reached.include?(v)

					correspond[v] ||= lg.add_node 
					correspond[e] = lg.add_edge(correspond[u], correspond[v])

					next_queue << v unless reached.include?(v)	
				}
			end	

			break if next_queue.empty?
			next_queue.each{|v| reached << v}
			current_queue = next_queue
		end

		nil
	end
end

def get_integers
	gets.split(" ").map(&:to_i)
end

n, m = get_integers
loop {

	g = Graph.new

	indent = -1
	stack = []
	name_to_node = {}
	n.times {
		gets =~ /^(\s*)(\w+)$/
		indent = $1.size
		stack.pop until stack.size <= indent
		v = g.add_node($2)
		g.add_edge(stack.last, v) if stack.size > 0
		stack << v
		name_to_node[v.label] = v
	}

	m.times {
		gets =~ /^(\w+) is \w+ (\w+) of (\w+)\.$/
		u = name_to_node[$1]
		relation = $2
		v = name_to_node[$3]
		
		bool = false
		case relation
		when "descendant"
			bool = Graph::get_path_bfs(v, u)
		when "ancestor"
			bool = Graph::get_path_bfs(u, v)
		when "child"
			bool = !u.incomings.empty? && u.incomings.all?{|e| e.from == v}
		when "parent"
			bool = !v.incomings.empty? && v.incomings.all?{|e| e.from == u}
		when "sibling"
			bool = u.incomings == v.incomings
		end
		puts bool ? "True" : "No"
	}

	n, m = get_integers
	break if n == 0
	puts
}