#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
#define bpc __builtin_popcount

int main()
{
	freopen("DATA3.txt", "r", stdin);
	freopen("OUT3.txt", "w", stdout);
	
	map<string,int> lookup;
	lookup["gal"] = 1;
	lookup["qt"] = 4;
	lookup["pt"] = 8;
	lookup["gill"] = 32;
	lookup["oz"] = 160;
	
	for (int T = 0; T < 5; T++)
	{
		int units;
		string first, second, temp;
		cin >> units >> first >> temp >> second;
		cout << units * lookup[second] / lookup[first] << endl;
	}
}
