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

int par[1010];
int gen[1010];
char namex[99], namey[99], rel[99];

bool parent(int x, int y){
	return par[y] == x;
}

bool sibling(int x, int y){
	return par[x] == par[y];
}

bool ancestor(int x, int y){
	while(y != -1){
		y = par[y];
		if( x == y ) return true;
	}
	return false;
}

int main(){
	int n, m;
	string str;

	while( cin >> n >> m, n != 0 ){
		cin.ignore();
		
		map<string,int> names;
		gen[0] = -1;
		
		int indent = 0;
		
		for(int i = 0; i < n; ++i){
			getline(cin, str);
			sscanf(str.c_str(), " %n%s", &indent, namex);
			
			int k = names.size();
			names[namex] = k;
			
			par[k] = gen[indent];
			gen[indent + 1] = k;
		}

		for(int i = 0; i < m; ++i){
			getline(cin, str);
			sscanf(str.c_str(), "%s%*s%*s %s%*s %[^.]", namex, rel, namey);
			
			int x = names[namex];
			int y = names[namey];
			bool f = false;

			switch( rel[0] ){
				case 'c':
					f = parent(y, x);
					break;
				case 'p':
					f = parent(x, y);
					break;
				case 's':
					f = sibling(x, y);
					break;
				case 'd':
					f = ancestor(y, x);
					break;
				case 'a':
					f = ancestor(x, y);
					break;
			}
			
			puts( f ? "True" : "False" );
		}

		puts("");
	}
}