#include "stdafx.h"
#include "stdio.h"
#include "iostream"
#include "string.h"
#include "string"
using namespace std;
int arr[
1000];
void find(
int a,
int b){
int flag =
0;
if(!flag){
int count =
0;
int temp_a = a;
while(arr[temp_a]!=-
1){
count++;
if(arr[temp_a]!=b){
temp_a = arr[temp_a];
}
else{
if(count>
1){
for(
int i =
2;i<count;i++)
cout<<
"great-";
cout<<
"grandparent"<<endl;
}
else
cout<<
"parent"<<endl;
flag =
1;
break;
}
}
}
if(!flag){
int count =
0;
int temp_b = b;
while(arr[temp_b]!=-
1){
count++;
if(arr[temp_b]!=a){
temp_b = arr[temp_b];
}
else{
if(count>
1){
for(
int i =
2;i<count;i++)
cout<<
"great-";
cout<<
"grandchild"<<endl;
}
else
cout<<
"child"<<endl;
flag =
1;
break;
}
}
}
if(!flag)
cout<<
"-"<<endl;
}
int main()
{
int n,m;
while(
cin>>n>>m && (m||n)){
string a;
memset(arr,-
1,
sizeof(arr));
while(n--){
cin>>a;
if(a[
1]!=
'-')
arr[a[
1]-
'A'] = a[
0]-
'A';
if(a[
2]!=
'-')
arr[a[
2]-
'A'] = a[
0]-
'A';
}
while(m--){
cin>>a;
find(a[
0]-
'A',a[
1]-
'A');
}
}
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-662527.html