#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

struct Info{
	char name[21];
	int parent;
	vector<int> children;
};

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;


	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

void func(int num_of_family,int num_of_statement){
	int index = 0,space_num,last_appeared[71],work_index;
	Info info[num_of_family];

	char line[100],work[21];

	scanf("%s",line);
	strcpy(info[0].name,line);
	info[0].parent = -1;
	last_appeared[0] = 0;
	getchar();

	for(int loop = 1; loop < num_of_family;loop++){
		fgets(line,100,stdin);
		for(space_num = 0; line[space_num] == ' ';space_num++);

		info[last_appeared[space_num-1]].children.push_back(++index);
		info[index].parent = last_appeared[space_num-1];

		work_index = 0;
		for(int i = space_num; line[i] != '\n' && line[i] != '\0';i++){
			work[work_index++] = line[i];
		}
		work[work_index] = '\0';

		strcpy(info[index].name,work);
		last_appeared[space_num] = index;
	}

	char X[21],is[3],buf1[6],buf2[15],buf3[15],Y[22];
	bool FLG;

	for(int loop = 0; loop < num_of_statement; loop++){
		scanf("%s %s %s %s %s %s",X,is,buf1,buf2,buf3,Y);

		for(int p = 0; Y[p] != '\0';p++){
			if(Y[p] == '.'){
				Y[p] = '\0';
			}
		}

		FLG = false;
		switch(buf2[0]){
		case 'c':
			for(int i = 0; i <= index; i++){
				if(strCmp(info[i].name,X)){
					if(info[i].parent != -1 && strCmp(info[info[i].parent].name,Y) == true){
						FLG = true;
					}
					break;
				}
			}
			break;
		case 'p': //X is the parent of Y
			for(int i = 0; i <= index; i++){
				if(strCmp(info[i].name,Y)){
					if(info[i].parent != -1 && strCmp(info[info[i].parent].name,X) == true){
						FLG = true;
					}
					break;
				}
			}
			break;
		case 's': //X is a silbling of Y
			for(int i = 0; i <= index; i++){
				if(strCmp(info[i].name,Y)){
					if(info[i].parent == -1)break;

					for(int k = 0; k < info[info[i].parent].children.size();k++){
						if(strCmp(info[info[info[i].parent].children[k]].name,X)){
							FLG = true;
							break;
						}
					}
					break;
				}
			}
			break;
		case 'd': //X is a descendant of Y
			for(int i = 0; i <= index; i++){
				if(strCmp(info[i].name,X)){
					int t = info[i].parent;

					while(t != -1){
						if(strCmp(info[t].name,Y)){
							FLG = true;
							break;
						}

						t = info[t].parent;
					}
					break;
				}
			}
			break;
		case 'a': //X is an ancestor of Y
			for(int i = 0; i <= index; i++){
				if(strCmp(info[i].name,Y)){
					int t = info[i].parent;

					while(t != -1){
						if(strCmp(info[t].name,X)){
							FLG = true;
							break;
						}

						t = info[t].parent;
					}
					break;
				}
			}
			break;

		}
		if(FLG){
			printf("True\n");
		}else{
			printf("False\n");
		}
	}

	printf("\n");
}


int main(){

	int num_of_family,num_of_statement;
	while(true){
		scanf("%d %d",&num_of_family,&num_of_statement);
		if(num_of_family == 0 && num_of_statement == 0)break;

		func(num_of_family,num_of_statement);
	}

	return 0;
}

Measured memory_bytes: 2764