#!/usr/bin/python
input = open('DATA3.txt', 'r')
output = open('OUT3.txt', 'w')
def convert(value,unit1,unit2):
	value = int(value)
	if unit1 == 'oz':
		if unit2 == 'oz':
			return value
		if unit2 == 'gill':
			return value / 5
		if unit2 == 'pt':
			return (value / 5) / 4
		if unit2 == 'qt':
			return ((value / 5) / 4) / 2
		if unit2 == 'gal':
			return (((value / 5) / 4) / 2) / 4
	if unit1 == 'gill':
		if unit2 == 'gal':
			return value
		if unit2 == 'oz':
			return value * 5
		if unit2 == 'pt':
			return value / 4
		if unit2 == 'qt':
			return (value / 4) / 2
		if unit2 == 'gal':
			return ((value / 4) / 2) / 4
	if unit1 == 'pt':
		if unit2 == 'pt':
			return value
		if unit2 == 'gill':
			return value * 4
		if unit2 == 'oz':
			return (value * 4) * 5
		if unit2 == 'qt':
			return value / 2
		if unit2 == 'gal':
			return (value / 2) / 4
	if unit1 == 'qt':
		if unit2 == 'qt':
			return value
		if unit2 == 'pt':
			return value * 2
		if unit2 == 'gill':
			return (value * 2) * 4
		if unit2 == 'oz':
			return ((value * 2) * 4) * 5
		if unit2 == 'gal':
			return value / 4
	if unit1 == 'gal':
		if unit2 == 'gal':
			return value
		if unit2 == 'qt':
			return value * 4
		if unit2 == 'pt':
			return (value * 4) * 2
		if unit2 == 'gill':
			return ((value * 4) * 2) * 4
		if unit2 == 'oz':
			return (((value * 4) * 2) * 4) * 5
#FUCKING HARD CODING!!!!!!! FUCK!!!!!
for lists in input.readlines():
	list = lists.split()
	value = list[0]
	unit1 = list[1]
	unit2 = list[3]
	output.writelines(str(convert(value,unit1,unit2)) + "\n")
output.close()

