Cousin's Aunt

Time Limit : 8 sec, Memory Limit : 65536 KB

Problem I: Cousin's Aunt

Sarah is a girl who likes reading books.

One day, she wondered about the relationship of a family in a mystery novel. The story said,

  • B is Afs fatherfs brotherfs son, and
  • C is Bfs aunt.

Then she asked herself, gSo how many degrees of kinship are there between A and C?h

There are two possible relationships between B and C, that is, C is either Bfs fatherfs sister or Bfs motherfs sister in the story. If C is Bfs fatherfs sister, C is in the third degree of kinship to A (Afs fatherfs sister). On the other hand, if C is Bfs motherfs sister, C is in the fifth degree of kinship to A (Afs fatherfs brotherfs wifefs sister).

You are a friend of Sarahfs and good at programming. You can help her by writing a general program to calculate the maximum and minimum degrees of kinship between A and C under given relationship.

The relationship of A and C is represented by a sequence of the following basic relations: father, mother, son, daughter, husband, wife, brother, sister, grandfather, grandmother, grandson, granddaughter, uncle, aunt, nephew, and niece. Here are some descriptions about these relations:

  • Xfs brother is equivalent to Xfs fatherfs or motherfs son not identical to X.
  • Xfs grandfather is equivalent to Xfs fatherfs or motherfs father.
  • Xfs grandson is equivalent to Xfs sonfs or daughterfs son.
  • Xfs uncle is equivalent to Xfs fatherfs or motherfs brother.
  • Xfs nephew is equivalent to Xfs brotherfs or sisterfs son.
  • Similar rules apply to sister, grandmother, granddaughter, aunt and niece.

In this problem, you can assume there are none of the following relations in the family: adoptions, marriages between relatives (i.e. the family tree has no cycles), divorces, remarriages, bigamous marriages and same-sex marriages.

The degree of kinship is defined as follows:

  • The distance from X to Xfs father, Xfs mother, Xfs son or Xfs daughter is one.
  • The distance from X to Xfs husband or Xfs wife is zero.
  • The degree of kinship between X and Y is equal to the shortest distance from X to Y deduced from the above rules.

Input

The input contains multiple datasets. The first line consists of a positive integer that indicates the number of datasets.

Each dataset is given by one line in the following format:

      C is A(fs relation)*

Here, relation is one of the following:

father, mother, son, daughter, husband, wife, brother,
sister, grandfather, grandmother, grandson, granddaughter, uncle, aunt, nephew, niece.

An asterisk denotes zero or more occurance of portion surrounded by the parentheses. The number of relations in each dataset is at most ten.

Output

For each dataset, print a line containing the maximum and minimum degrees of kinship separated by exact one space. No extra characters are allowed of the output.

Sample Input

7
C is Afs fatherfs brotherfs sonfs aunt
C is Afs motherfs brotherfs sonfs aunt
C is Afs sonfs motherfs motherfs son
C is Afs auntfs niecefs auntfs niece
C is Afs fatherfs sonfs brother
C is Afs sonfs sonfs mother
C is A

Output for the Sample Input

5 3
5 1
2 2
6 0
2 0
1 1
0 0

Source: ACM International Collegiate Programming Contest , ACM-ICPC Japan Alumni Group Practice Contest 2008, 2008-10-19
http://acm-icpc.aitea.net/