/*
AizuOnline A1217
Title Family tree
RE
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int n,m;
struct p_str
{
        char name[21];
        int  parent;
        int  level;       //no of indent
} person[1001];
int person_ptr;
char readbuffer[72];
//
int c_sp(char *s)
{
        int i;
        int cnt;

        for(i=0;s[i];i++)
                if(s[i]!=' ')
                        break;
        return(i);
}
void print_tree()
{
        int i;
        printf("----------------------\n");
        for(i=0;i<person_ptr;i++)
        {
                printf("%d %s",person[i].level,person[i].name);
                if(i)
                        printf("(%s)",person[person[i].parent].name);
                printf("\n");
        }
}
int name2sno(char * name)
{
        int i;
        for(i=0;i<person_ptr;i++)
                if(0==strcmp(name,person[i].name))
                        return(i);
        return(-1);
}
int check_relation(char * sub,char * rel,char *obj)
{
        int sn,on;
        sn=name2sno(sub);
        on=name2sno(obj);
        if(0==strcmp(rel,"parent"))
                return(person[on].parent == sn);
        if(0==strcmp(rel,"child"))
        {
                return(person[sn].parent == on);
        }
        if(0==strcmp(rel,"sibling"))
        {
                return(person[sn].parent == person[on].parent);
        }
        if(0==strcmp(rel,"ancestor"))
        {
        LOOP:
                if(person[on].parent < 0)
                        return(0);
                if(sn== person[on].parent)
                        return(-1);
                on=person[on].parent;
                goto LOOP;
        }
        if(0==strcmp(rel,"descendant"))
        {
        LOOP2:
                if(person[sn].parent < 0)
                        return(0);
                if(on== person[sn].parent)
                        return(-1);
                sn=person[sn].parent;
                goto LOOP2;
        }

        return(0);
}
main()
{
        int i,j;
        int nsp;  // no of leading space
        char *subject;
        char *object;
        char *relation;

        while(EOF!=scanf("%d %d\n",&n,&m) && (n||m))
        {       
                //printf("NM %d %d \n",n,m);        
                person_ptr=0;
                for(i=0;i<n;i++)
                {
                        fgets(readbuffer,sizeof(readbuffer),stdin);
                        if(readbuffer[strlen(readbuffer)-1]=='\n')
                                readbuffer[strlen(readbuffer)-1]='\0';
                        nsp=c_sp(readbuffer);
                        //printf("msp:%d %s\n",nsp,readbuffer);
                        strcpy(&person[person_ptr].name[0],&readbuffer[nsp]);
                        person[person_ptr].level=nsp;       
                        if(person_ptr==0)
                                person[person_ptr].parent=-1;  //root
                        else
                                for(j=person_ptr-1;j>=0;j--)
                                        if(person[j].level==nsp-1)
                                        {
                                                person[person_ptr].parent=j;
                                                break;
                                        }
                        person_ptr++;
                }
#ifdef DEBUG
                print_tree();
#endif
                for(i=0;i<m;i++)
                {
                        fgets(readbuffer,sizeof(readbuffer),stdin);
                        subject=strtok(readbuffer," ");
                        (void)strtok(NULL," ");         // is 
                        (void)strtok(NULL," ");         // kansi
                        relation=strtok(NULL," ");
                        (void)strtok(NULL," ");         // of
                        object=strtok(NULL,".");
#ifdef DEBUG
                        printf("%s %s %s\n",subject,relation,object);
#endif
                        printf("%s\n",check_relation(subject,relation,object)?"True":"False");
                }
                printf("\n");
        }
}