#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, string>
const int INF = INT_MAX / 2;
const int MAX_M = 1010;

P cntSpace(string str){
    int cnt = 0;
    while(str[cnt] == ' ') cnt++;
    return P(cnt, str.substr(cnt));
}

bool isParent(int x, int y, vector<int> parent){
    if(parent[y] == x) return true;
    else return false;
}

bool checkQ(string str, map<string, int> list_i, vector<int> parent){
    stringstream ss(str);
    vector<string> vec;
    string tmp;
    while(ss >>tmp) vec.push_back(tmp);

    int x = list_i[vec[0]];
    int y = list_i[vec[5].erase(vec[5].size() - 1)];

    if(vec[3] == "child") return isParent(y, x, parent);
    if(vec[3] == "parent") return isParent(x, y, parent);
    if(vec[3] == "sibling") return parent[x] == parent[y];
    if(vec[3] == "descendant"){
        int now_x = x;
        while(parent[now_x] != -1){
            if(isParent(y, now_x, parent) == true) return true;
            now_x = parent[now_x];
        }
        return false;
    }
    if(vec[3] == "ancestor"){
        int now_y = y;
        while(parent[now_y] != -1){
            if(isParent(x, now_y, parent) == true) return true;
            now_y = parent[now_y];
        }
        return false;
    }
}



int main(){
    int m, n;
    while(cin >>m >>n && (n && m)){
        string name_line;
        getline(cin, name_line);

        vector<int> parent(m);
        int current_parent_i[MAX_M];
        map<string, int> list_i;

        parent[0] = -1;

        REP(i, m){
            getline(cin, name_line);

            P rank_and_name = cntSpace(name_line);
            current_parent_i[rank_and_name.first + 1] = i;
            list_i[rank_and_name.second] = i;

            if(i != 0){
                int now_parent = current_parent_i[rank_and_name.first];
                parent[i] = now_parent;
            }
        }

        REP(i, n){
            string q;
            getline(cin, q);
            bool ans = checkQ(q, list_i, parent);
            if(ans) cout <<"True" <<endl;
            else cout <<"False" <<endl;
        }
        cout <<endl;
    }
    return 0;
}