#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <ctype.h>
#include <stdio.h>

using namespace std;

int main (){
	ifstream fin ("DATA3.txt");
	ofstream fout ("OUT3.txt");		
	
	string first, in, second;
	int i, a, z;
	
	for (z=0; z<5; ++z){
		fin >> a;
		fin >> first;
		fin >> in;
		fin >> second;
		if (first[0]=='o'){
			if (second[0]=='g' && second[1]=='i'){
				fout << a/5 << endl;
			}
			if (second[0]=='g' && second[1]=='a'){
				fout << a/160 << endl;
			}
			if (second[0]=='q'){
				fout << a/40 << endl;
			}
			if (second[0]=='p'){
				fout << a/20 << endl;
			}
			if (second[0]=='o'){
				fout << a << endl;
			}
		}
		if (first[0]=='g' && first[1]=='i'){
			if (second[0]=='g' && second[1]=='i'){
				fout << a << endl;
			}
			if (second[0]=='g' && second[1]=='a'){
				fout << a/32 << endl;
			}
			if (second[0]=='q'){
				fout << a/8 << endl;
			}
			if (second[0]=='p'){
				fout << a/4 << endl;
			}
			if (second[0]=='o'){
				fout << a*5 << endl;
			}
		}
		if (first[0]=='p'){
			if (second[0]=='g' && second[1]=='i'){
				fout << a*4 << endl;
			}
			if (second[0]=='g' && second[1]=='a'){
				fout << a/8 << endl;
			}
			if (second[0]=='q'){
				fout << a/2 << endl;
			}
			if (second[0]=='p'){
				fout << a << endl;
			}
			if (second[0]=='o'){
				fout << a*20 << endl;
			}
		}
		if (first[0]=='q'){
			if (second[0]=='g' && second[1]=='i'){
				fout << a*8 << endl;
			}
			if (second[0]=='g' && second[1]=='a'){
				fout << a/4 << endl;
			}
			if (second[0]=='q'){
				fout << a << endl;
			}
			if (second[0]=='p'){
				fout << a*2 << endl;
			}
			if (second[0]=='o'){
				fout << a*40 << endl;
			}
		}
		if (first[0]=='g' && first[1]=='a'){
			if (second[0]=='g' && second[1]=='i'){
				fout << a*32 << endl;
			}
			if (second[0]=='g' && second[1]=='a'){
				fout << a << endl;
			}
			if (second[0]=='q'){
				fout << a*4 << endl;
			}
			if (second[0]=='p'){
				fout << a*8 << endl;
			}
			if (second[0]=='o'){
				fout << a*160 << endl;
			}
		}	
	}
	
	fout.close();
	fin.close();
	return 0;
}

