#include #include int n, m; string str[1000]; string parent[1000]; int indent[1000]; string getparent( string child ){ for( int i = 0; i < n; i++ ){ // cout << str[i]; if( str[i] == child ){ return parent[i]; } } return "no parent"; } int ischild( string child, string parent ){ // cout << getparent(child) << parent; if( getparent(child) == parent ) return 1; else return 0; } int isancestor( string ancestor, string shison ) { // while( shison != "no parent" ){ // shison = getparent(shison); while( ( shison = getparent(shison) ) != "no parent" ){ if(shison == ancestor) return 1; } return 0; } #define TF(a) (cout << ((a) ? "True" : "False") << endl) void main() { /* int n, m; cin >> n >> m; string str[1000]; string parent[1000]; int indent[1000] =0; */ int first = 1; while( cin >> n >> m && n && m ) { if(!first) cout << endl; first = 0; // cout << n << m; char tmp[99999]; cin.getline(tmp, 9999); for( int i = 0; i < n; i++ ){ indent[i] = 0; cin.getline( tmp, 99999 ); str[i] = tmp; for( indent[i] = 0; str[i][0] == ' '; indent[i]++ ) str[i] = str[i].substr(1,str[i].length()-1);; for ( int j = i; j >= 0; j-- ){ if( indent[j] == indent[i] - 1 ){ parent[i] = str[j]; break; } } } for( int i = 0; i < m; i++ ){ string name1, t1, t2, relation, t3, name2; cin >> name1 >> t1 >> t2 >> relation >> t3 >> name2; name2 = name2.substr(0,0+name2.length()-1); // cout << name1 << endl << name2 << endl; if( relation == "child" ) TF(ischild(name1,name2)); else if( relation == "parent" ) TF(ischild(name2,name1)); else if( relation == "sibling" ) TF( getparent(name1) == getparent(name2) ); else if( relation == "descendant" ) TF( isancestor(name2,name1)); else if( relation == "ancestor" ) TF( isancestor(name1,name2)); } } cout << endl; }