### subroutines

def check_relation(prts, a, b, rel)	# check if 'a is rel of b' is true
  case rel
  when 'child'
    return (prts[a] == b)
  when 'parent'
    return (prts[b] == a)
  when 'ancestor'
    while prts[b]
      return true if (prts[b] == a)
      b = prts[b]
    end
    return false
  when 'descendant'
    while prts[a]
      return true if (prts[a] == b)
      a = prts[a]
    end
    return false
  when 'sibling'
    return (prts[a] == prts[b])
  else
    puts "undefined relation: #{rel}"
  end
  nil
end

### main

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

  prts = {}
  prt = cur = nil
  idt = 0
  
  n.times do
    line = gets.rstrip
    name = line.lstrip
    i = line.index(/[^ ]/)
    #p [name, i, prt, idt]

    if idt < i
      idt = i
      prt = cur
    elsif idt > i
      idt = i
      prt = prts[prt]
    end

    prts[name] = prt
    cur = name
  end
  #p prts

  m.times do
    cols = gets.strip.split
    aname = cols[0]
    bname = cols[5].delete('.')
    rel = cols[3]
    #p [aname, bname, rel]

    puts (check_relation(prts, aname, bname, rel) ? 'True' : 'False')
  end
  puts
end