#include #include #include using namespace std; struct person_t { string name; int lv; public: person_t(string name, int lv) : name(name), lv(lv) { } person_t(void) { } }; static vector persons; bool is_ancestor(int x, int y, bool direct) { if(x > y) { return false; } for(int i = x + 1; i <= y; i++) { if(persons[i].lv <= persons[x].lv) { return false; } } if(direct) { return persons[x].lv + 1 == persons[y].lv; } else { return true; } } bool is_sibling(int x, int y) { int s = (x < y) ? x : y; int t = (x > y) ? x : y; for(int i = s; i <= t; i++) { if(persons[i].lv < persons[s].lv) { return false; } } return persons[s].lv == persons[t].lv; } int main(void) { int n, m; while(cin >> n >> m) { if(n == 0 && m == 0) break; string line; // dispose end-of-line marker getline(cin, line); // allocate slots for persons persons.resize(n); for(int i = 0; i < n; i++) { getline(cin, line); for(int j = 0; j < line.length(); j++) { if(line[j] != ' ') { persons[i].name = line.substr(j); persons[i].lv = j; break; } } } for(int i = 0; i < m; i++) { string sx, sy, rel; string dmy; cin >> sx >> dmy >> dmy >> rel >> dmy >> sy; sy = sy.substr(0, sy.length() - 1); int nx, ny; for(int j = 0; j < n; j++) { if(sx == persons[j].name) nx = j; if(sy == persons[j].name) ny = j; } bool ans; if(rel == "child") { ans = is_ancestor(ny, nx, true); } if(rel == "parent") { ans = is_ancestor(nx, ny, true); } if(rel == "sibling") { ans = is_sibling(nx, ny); } if(rel == "descendant") { ans = is_ancestor(ny, nx, false); } if(rel == "ancestor") { ans = is_ancestor(nx, ny, false); } cout << (ans ? "True" : "False") << endl; } cout << endl; } return 0; }