import java.io.*;
import java.util.*;

public class p3 {

	/**
	 * @param args
	 * @throws FileNotFoundException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
	int tot; String meas1; String meas2;
		File file = new File ("DATA3.txt");
		File file2 = new File ("OUT3.txt");
		FileWriter fw = new FileWriter (file2);
		Scanner scanner = new Scanner(file);
		for(int x = 0; x != 5; x++){
		tot = scanner.nextInt();
		meas1 = scanner.next();
		scanner.next();
		meas2 = scanner.next();
		if (meas1.equals("oz") && meas2.equals("oz")){
			tot = tot;
		}
		if (meas1.equals("oz") && meas2.equals("gill")){
			tot = tot / 5;
		}
		if (meas1.equals("oz") && meas2.equals("pt")){
			tot = tot / 20;
		}
		if (meas1.equals("oz") && meas2.equals("qt")){
			tot = tot / 40;
		}
		if (meas1.equals("oz") && meas2.equals("gal")){
			tot = tot /160;
		}
		if (meas1.equals("gill") && meas2.equals("oz")){
			tot = tot * 5;
		}
		if (meas1.equals("gill") && meas2.equals("gill")){
			tot = tot;
		}
		if (meas1.equals("gill") && meas2.equals("pt")){
			tot = tot * 5 / 20;
		}
		if (meas1.equals("gill") && meas2.equals("qt")){
			tot = tot * 5 / 40;
		}
		if (meas1.equals("gill") && meas2.equals("gal")){
			tot = tot * 5 /160;
		}
		if (meas1.equals("pt") && meas2.equals("oz")){
			tot = tot * 20;
		}
		if (meas1.equals("pt") && meas2.equals("gill")){
			tot = tot * 20 / 5;
		}
		if (meas1.equals("pt") && meas2.equals("pt")){
			tot = tot;
		}
		if (meas1.equals("pt") && meas2.equals("qt")){
			tot = tot * 20 / 40;
		}
		if (meas1.equals("pt") && meas2.equals("gal")){
			tot = tot * 20 / 160;
		}
		if (meas1.equals("qt") && meas2.equals("oz")){
			tot = tot * 40;
		}
		if (meas1.equals("qt") && meas2.equals("gill")){
			tot = tot * 40 / 5;
		}
		if (meas1.equals("qt") && meas2.equals("pt")){
			tot = tot * 40 / 20;
		}
		if (meas1.equals("qt") && meas2.equals("qt")){
			tot = tot;
		}
		if (meas1.equals("qt") && meas2.equals("gal")){
			tot = tot * 40 / 160;
		}
		if (meas1.equals("gal") && meas2.equals("oz")){
			tot = tot * 160;
		}
		if (meas1.equals("gal") && meas2.equals("gill")){
			tot = tot * 160 / 5;
		}
		if (meas1.equals("gal") && meas2.equals("pt")){
			tot = tot * 160 / 20;
		}
		if (meas1.equals("gal") && meas2.equals("qt")){
			tot = tot * 160 / 40;
		}
		if (meas1.equals("gal") && meas2.equals("gal")){
			tot = tot;
		}
		fw.write(tot+"\r\n");
		if (x != 4) scanner.nextLine();
		}
		
		fw.close();
	}

}

