#include <bits/stdc++.h>
using namespace std;
string t[13] = {"Ox", "Tiger", "Rabbit", "Dragon", "Snake", "Horse", 
    "Goat", "Monkey", "Rooster", "Dog", "Pig", "Rat"};   //存储生肖,字符串数组
int n;
string a, b, c, d, e, f, g, h;//待输入的字符串
//Mildred born in previous Dragon year from Bessie
map<string, int> ans;  //ans为牛的年份,map的使用特征
int main() {
    ans["Bessie"] = 0;
    cin >> n;
    while (n--) {
        cin >> a >> b >> c >> d >> e >> f >> g >> h;//多次输入的话最好别用数组
        if (d == "previous") {
            int k;
            for (k = ans[h] - 1;; k--) {   
                if (t[(k + 12 * 50000) % 12] == e) break;   
            }
            ans[a] = k;
        }
        else {
            int k;
            for (k = ans[h] + 1; ; k++) {
                if (t[(k + 12 * 50000) % 12] == e) break;
            }
            ans[a] = k;
        }
    }
    cout << abs(ans["Elsie"]) << endl;
}