C language source code: [cpp] # include <stdio. h> int main () {int n, m, I, T [26], a, B, num, j, k; char s [4]; scanf ("% d", & n, & m); while (n | m) {for (I = 0; I <26; I ++) T [I] =-1; for (I = 0; I <n; I ++) {scanf ("% s", s ); if (s [1]> = 'A' & s [1] <= 'Z ') T [s [1]-'a'] = s [0]-'A '; if (s [2]> = 'A' & s [2] <= 'Z ') T [s [2]-'a'] = s [0]-'A';} for (k = 0; k <m; k ++) {scanf ("% s", s); a = s [0]-'A'; B = s [1]-'A'; num = 0; I = a; while (I! = B & T [I]! =-1) {I = T [I]; num ++;} if (I = B) {if (num = 1) printf ("parent \ n"); else if (num = 2) printf ("grandparent \ n"); else {for (j = 1; j <= num-2; j ++) printf ("great-"); printf ("grandparent \ n") ;}} else {I = B; while (I! = A & T [I]! =-1) {I = T [I]; num ++;} if (I = a) {if (num = 1) printf ("child \ n"); else if (num = 2) printf ("grandchild \ n"); else {www.2cto.com for (j = 1; j <= num-2; j ++) printf ("great-"); printf ("grandchild \ n") ;}} else printf ("-\ n ");}} scanf ("% d", & n, & m );}}