require 'set'

class Graph
	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_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
end

class Forest < Graph
	def add_node(label = nil)
		Node.new(label)
	end

	def add_edge(u, v)
		raise "multiple in-edge" unless v.incomings.empty?
		e = Edge.new(u, v)
		u.outgoings << e
		v.incomings << e
		e
	end

	class Node < Graph::Node
		def parent
			a = incomings.to_a.map(&:from)
			a.empty? ? nil : a[0]
		end
	end

	class Edge < Graph::Edge
	end
end

loop {
	n, m = gets.split(" ").map(&:to_i)
	break if n == 0

	g = Forest.new
	stack = []
	name_to_node = {}

	n.times {
		gets =~ /^(\s*)(\w+)$/
		stack.pop until stack.size <= $1.size
		v = g.add_node($2)
		g.add_edge(stack.last, v) unless stack.empty?
		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_dfs(v, u)
		when "ancestor"
			bool = Graph::get_path_dfs(u, v)
		when "child"
			bool = u.parent == v
		when "parent"
			bool = v.parent == u
		when "sibling"
			bool = u.parent == v.parent
		end
		puts bool ? "True" : "False"
	}

	puts
}