#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int getDepth(string &name) {
    int depth = 0;
    while (name[depth] == ' ') {
        depth++;
    }
    name = name.substr(depth);
    return depth;
}

#include <map>

void dfs(vector<vector<int>> &G, int v, vector<bool> &used) {
    if (v == -1 || used[v]) return;
    used[v] = true;
    for (auto &vv : G[v]) {
        dfs(G, vv, used);
    }
}

vector<string> split(string s) {
    s += " ";
    int prev = 0;
    vector<string> res;
    REP(i, 0, s.size()) {
        if (s[i] == ' ') {
            res.push_back(s.substr(prev, i - prev));
            prev = i + 1;
        }
    }
    return res;
}

string P(bool f) {
    return (f ? "True" : "False");
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    while (cin >> n >> m, n + m) {
        vector<string> name(n);
        vector<int> depth(n);
        REP(i, 0, n) {
            string in;
            do {
                getline(cin, in);
            } while (in.size() == 0);
            depth[i] = getDepth(in);
            name[i] = in;
        }
        map<string, int> name2num;
        REP(i, 0, n) {
            name2num[name[i]] = i;
        }
        vector<vector<int>> Graph(n);
        {
            int prev = 0;
            vector<int> stk;
            Graph[0].push_back(-1);
            REP(i, 1, n) {
                if (depth[i - 1] < depth[i]) {
                    REP (_, 0, depth[i] - depth[i - 1]) {
                        stk.push_back(prev);
                        prev = i - 1;
                    }
                } else if (depth[i - 1] > depth[i]) {
                    REP (_, 0, depth[i -1] - depth[i]) {
                        prev = stk.back();
                        stk.pop_back();
                    }
                }
                Graph[i].push_back(prev);
            }
        }
        auto connected = make_v(n, n, false);
        REP(i, 0, n) {
            dfs(Graph, i, connected[i]);
        }
        REP(i, 0, m) {
            string in;
            do {
                getline(cin, in);
            } while (in.size() == 0);
            auto parse = split(in);
            string x = parse[0], y = parse.back();
            y = y.substr(0, y.size() - 1);
            string ob = parse[3];
            int ix = name2num[x], iy = name2num[y];
            if (ob == "child") {
                cout << P(Graph[ix][0] == iy) << endl;
            } else if (ob == "parent"){
                cout << P(Graph[iy][0] == ix) << endl;
            } else if (ob == "sibling") {
                cout << P(Graph[ix][0] == Graph[iy][0]) << endl;
            } else if (ob == "descendant") {
                cout << P(connected[ix][iy]) << endl;
            } else if (ob == "ancestor") {
                cout << P(connected[iy][ix]) << endl;
            } else {
                dump("error");
            }
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3496