Year of the Cow#11207

Year of the Cow

1 second
128 megabytes
Medium

As we know, the zodiac animals for Chinese calendar years follow a -year cycle: Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig, Rat, and then Ox again.

Bessie the cow is proud to say she was born in a year of the Ox, many years ago. Her friend Elsie wants to know how many years apart from Bessie she was born, and hopes you can help her deduce this by looking at relationships between the birth years of several cows on the farm.

Input

The first line contains an integer (1 \le n \le 100). Each of the next lines contains an -word phrase specifying the relationship between the birth years of two cows. It is of the form

"Mildred born in previous Dragon year from Bessie",

or

"Mildred born in next Dragon year from Bessie"

The last word is the name of a cow on the farm, which is either "Bessie" or a cow that has already been mentioned in a previous line of input.

The first word is the name of a cow on the farm who is not "Bessie" and who has not yet been mentioned in the input. All cow names have at most characters that are in the range or .

The -th word is one of the zodiac animals above.

The -th word is either "previous" or "next". For example, if the phrase is "Mildred born in previous Dragon year from Bessie", then Mildred's year of birth was the Dragon year closest to and strictly before (not equal to) Bessie's birth year.

Output

Output the number of years by which Bessie and Elsie's birth years differ. It is guaranteed that this number can be determined by the input given.

Examples

Example 1

Loading
Loading

Note

In the input above,

  • Elsie was born years before Bessie.

  • Mildred was born years before Bessie.

  • Gretta was born years before Bessie.

  • Paulina was born years after Bessie.