import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
object Main extends App {
  import scala.io.StdIn._

  val isChildOf = """^(\w+) is a child of (\w+).$""".r
  val isParentOf = """^(\w+) is the parent of (\w+).$""".r
  val isSiblingOf = """^(\w+) is a sibling of (\w+).$""".r
  val isDescendantOf = """^(\w+) is a descendant of (\w+).$""".r
  val isAncestorOf = """^(\w+) is an ancestor of (\w+).$""".r
  solve
  def solve: Unit = {
    val Array(personSize, querySize) = readLine.trim.split(' ').map(_.toInt)
    if (personSize == 0) return
    val persons = new ArrayBuffer[List[Person]]()
    val map = new mutable.HashMap[String, Person]()
    for (_ ← 0 until personSize){
      readLine.span(_ == ' ') match {
        case (k, name) ⇒
          if (persons.size <= k.length) persons.append(Nil)
          val p = if (k.length == 0) {
            Person()
          }else {
            val p = Person()
            p.ancestor = Some(persons(k.length - 1).head)
            p
          }
          persons(k.length) ::= p
          map.put(name, p)
      }
    }
    for (_ ← 0 until querySize){
      println(readLine.trim match {
        case a isChildOf b ⇒
          if (map(a).isChildOf(map(b))) "True"
          else "False"
        case a isParentOf b ⇒
          if (map(a).isParentOf(map(b))) "True"
          else "False"
        case a isSiblingOf b ⇒
          if (map(a).isSiblingOf(map(b))) "True"
          else "False"
        case a isDescendantOf b ⇒
          if (map(a).isDescendantOf(map(b))) "True"
          else "False"
        case a isAncestorOf b ⇒
          if (map(a).isAncestorOf(map(b))) "True"
          else "False"
        case _ ⇒ ???
      })
    }
    println()
    solve
  }
  object Person{
    def apply(): Person = new Person()
  }
  class Person(var ancestor: Option[Person] = None) {
    def isSiblingOf(that: Person): Boolean = {
      ancestor.flatMap(person ⇒ that.ancestor.map(_ == person)).getOrElse(false)
    }
    def isChildOf(that: Person): Boolean = {
      ancestor.contains(that)
    }
    def isParentOf(that: Person): Boolean = {
      that.ancestor.contains(this)
    }
    def isDescendantOf(that: Person): Boolean = {
      isChildOf(that) || ancestor.exists(_.isDescendantOf(that))
    }
    def isAncestorOf(that: Person): Boolean = {
      that.isDescendantOf(this)
    }
  }
}
