Олимпиадный тренинг

Задача 38138. Year of the Cow


The Chinese calendar is known to follow a 12-year cycle: Ox(Ox), Tiger(Tiger), Rabbit(Rabbit), Dragon(Dragon), Snake(Snake), Horse(Horse), Goat(Goat) , Monkey(Monkey), Rooster(Rooster), Dog(Dog), Pig(Pig), Rat(Rat), and then Ox again. 
For many years, Besi the cow has been proud that she was born in the year of the Ox. Her friend Elsa wants to know how many years her birth is from Besie's and hopes you can help her find it out based on the relationship between the birth dates of some of the cows on the farm.



Input
The first line of input contains an integer N (\(1<=N<=100\)). Each of the following N lines contains an 8-word phrase indicating the relationship between the birth dates of the two cows. In the following form

"Mildred born in previous Dragon year from Bessie",

or

"Mildred born in next Dragon year from Bessie" (previous - previous, next-next).

The last word is the name of the cow, which is either Bessie or the cow previously mentioned in the previous input line.
The first word is the name of a cow that is not Bessie and has not yet been mentioned in the input. All cow names have a maximum of 10 characters a..z or A..Z.

The 5th word is one of the zodiac signs mentioned earlier.

4th word or "previous" or "next". For example, the phrase "Mildred born in previous Dragon year from Bessie", means that the year of birth of Mildred was the year of the Dragon (Dragon), the closest and strictly earlier (not equal) to the year of Bessie's birth.



Imprint
Output the number of years by which the birthdays of Besya and Elsa differ. It is guaranteed that this number can be determined from the input.
 
 
Examples
# Input Output Note
1 4
Mildred born in previous Dragon year from Bessie
Gretta born in previous Monkey year from Mildred
Elsie born in next Ox year from Gretta
Paulina born in next Dog year from Bessie
12

In the example above

  • Elsie was born 12 years before Bessie.
  • Mildred was born 9 years before Bessie.
  • Gretta was born 17 years before Bessie.
  • Paulina was born 9 years before Bessie.