#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;


struct Person {
  string name;
  Person *parent;
};

const int MAXN = 1005;
int N, M;
map<string, Person*> conv;
Person root, person[MAXN];

void init() {
  conv.clear();
  root.name = "root";
  root.parent = NULL;
}

bool child(Person *a, Person *b) { // a is child of b
  return a->parent == b;
}

bool sibling(Person *a, Person *b) {
  return a->parent == b->parent;
}

bool descendant(Person *a, Person *b) { // a is descendant of b
  while(a != NULL) {
    if(a->parent == b) return true;
    a = a->parent;
  }
  return false;
}

int main() {
  while(cin >> N >> M && (N|M)) {
    cin.ignore();
    init();
    Person *cp = &root;
    int depth = -1;
    for(int i = 0; i < N; ++i) {
      string line;
      getline(cin, line);
      int sp = 0;
      for(int j = 0; j < line.size() && line[j] == ' '; ++j, ++sp);

      Person &c = person[i];
      c.name = line.substr(sp);
      conv[c.name] = &person[i];

      if(sp > depth) {
        c.parent = cp;
      } else {
        for(int j = 0; j < depth-sp; ++j) {
          cp = cp->parent;
        }
        c.parent = cp->parent;
      }
      cp = &c;
      depth = sp;
    }

    while(M--) {
      string x, y, type;
      string dumy;
      cin >> x >> dumy >> dumy >> type >> dumy >> y;
      y = y.substr(0, y.size()-1);
      bool output = false;
      if(0) {
      } else if(type == "child") {
        output = child(conv[x], conv[y]);
      } else if(type == "parent") {
        output = child(conv[y], conv[x]);
      } else if(type == "sibling") {
        output = sibling(conv[x], conv[y]);
      } else if(type == "descendant") {
        output = descendant(conv[x], conv[y]);
      } else if(type == "ancestor") {
        output = descendant(conv[y], conv[x]);
      }
      cout << (output ? "True" : "False") << endl;
    }
    cout << endl;
  }
  return 0;
}