def is_ancestor?(name1, name2)
  return true if name2 == @top
  p = name1
  while p != @top
    p = @parent[p]
    return true if p == name2
  end
  false
end

loop do
  n, m = gets.split.map(&:to_i)
  break if n == 0
  @parent = {}
  cur_gen = 0
  @top = gets.chomp
  current = [@top]
  (n-1).times do
    name = gets.chomp
    gen = name.count(' ')
    name.delete!(' ')
    @parent[name] = current[gen - 1]
    current[gen] = name
    cur_gen = gen
  end

  m.times do
    s = gets.chomp.chop.split
    case s[3]
    when 'child'
      puts @parent[s[0]] == s[5] ? 'True' : 'False'
    when 'parent'
      puts @parent[s[5]] == s[0] ? 'True' : 'False'
    when 'sibling'
      puts @parent[s[0]] == @parent[s[5]] ? 'True' : 'False'
    when 'descendant'
      puts is_ancestor?(s[0], s[5]) ? 'True' : 'False'
    when 'ancestor'
      puts is_ancestor?(s[5], s[0]) ? 'True' : 'False'
    end
  end
  puts
end