/*
ID: alefar3142
LANG: JAVA
PROG: ride
*/
import java.util.*;
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.io.*;
import javax.swing.*;
public class ride  {
	
	/*5 fluid ounce (oz)	1 gill (gill)
4 gill (gill)	1 pint (pt)
2 pint (pt)	1 quart (qt)
4 quart (qt)	1 gallon (gal)*/

	public static void main(String args[])throws IOException
	{
	
    BufferedReader rer = new BufferedReader(new FileReader("DATA3.txt"));
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("OUT3.txt")));
 //oz,gill,pt,qt,gal
 
 HashMap<String,Integer> k= new HashMap<String, Integer>();
 k.put("oz",0);
 k.put("gill",1);
 k.put("pt",2);
 k.put("qt",3);
 k.put("gal",4);
 long t= System.currentTimeMillis();
double[][]conv=new double[5][5];
   conv[0][0]=1;
   conv[0][1]=0.2;
   conv[0][2]=0.05;
   conv[0][3]=0.025;
   conv[0][4]=0.00625;
   conv[1][0]=5.0;
   conv[1][1]=1;
   conv[1][2]=.25;
   conv[1][3]=0.125;
   conv[1][4]=0.03125;
   conv[2][0]=20;
   conv[2][1]=4.0;
   conv[2][2]=1;
   conv[2][3]=0.5;
   conv[2][4]=0.125;
   conv[3][0]=32;
   conv[3][1]=8;
   conv[3][2]=2;
   conv[3][3]=1;
   conv[3][4]=0.25;
   conv[4][0]=160;
   conv[4][1]=32;
   conv[4][2]=8;
   conv[4][3]=4;
   conv[4][4]=1;
   
   for(int i=0;i<5;i++)
     {
     	String[] st= rer.readLine().split(" ");
     	String a=st[1];
     	String b=st[3];
     	int m=Integer.parseInt(st[0]);
     	   int x=k.get(a);
     	   int y=k.get(b);
     	   out.write((int)(m*conv[x][y])+"\n");
     }


 rer.close();
out.close();

  

System.out.println("time:" +" " +(System.currentTimeMillis()-t));
}




}

	

