// Arup Guha
// 3/5/2021
// Solution to 2021 February USACO Bronze Problem: Year of the Cow

import java.util.*;

public class yearcow {

	// Look up table of years 0 to 11.
	final public static String[] ANIMALS = {"Ox", "Tiger", "Rabbit", "Dragon",
	"Snake", "Horse", "Goat", "Monkey", "Rooster", "Dog", "Pig", "Rat"};

	public static HashMap<String,Integer> map;
	public static HashMap<String,Integer> yearMap;
	
	public static void main(String[] args) {
	
		// Link animals to years.
		map = new HashMap<String,Integer>();
		for (int i=0; i<ANIMALS.length; i++)
			map.put(ANIMALS[i], i);
			
		// Bessie was born in year 0.
		yearMap = new HashMap<String,Integer>();
		yearMap.put("Bessie", 0);
	
		Scanner stdin = new Scanner(System.in);
		int nLines = stdin.nextInt();
		
		// Process the input.
		for (int loop=0; loop<nLines; loop++) {
		
			// Get the whole line.
			String[] line = new String[8];
			for (int  i=0; i<8; i++) line[i] = stdin.next();
			
			// We know the year the last cow was born in.
			int secondYear = yearMap.get(line[7]);
			
			// Get it's equivalent 0 to 11.
			int mod12Year = (12000+secondYear)%12;
			
			// Mod 12 year of new cows.
			int yearOffset = map.get(line[4]);
			
			// +1 is younger (later year born), -1 is older...
			int sign = line[3].equals("next") ? 1 : -1;
			
			// 12 is a special case...
			if (mod12Year == yearOffset) 
				yearMap.put(line[0], secondYear + 12*sign);
			
			// mods are difference.
			else {
				
				// My year comes later than known cow.
				if (yearOffset > mod12Year) {
					if (sign == 1)	yearMap.put(line[0], secondYear + yearOffset - mod12Year);
					else			yearMap.put(line[0], secondYear + yearOffset - mod12Year-12);
				}
				
				// My year comes before known cow, so math is off by 12.
				else {
					if (sign == 1)	yearMap.put(line[0], secondYear + yearOffset - mod12Year+12);
					else			yearMap.put(line[0], secondYear + yearOffset - mod12Year);				
				}
			}
		}
		
		// We want the absolute value of the year Elsie was born.
		System.out.println(Math.abs(yearMap.get("Elsie")));
	}
}