#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main( void )
{
	long n;
	while(cin >> n) {
		string str;
		int outCount = 0, point = 0, base = 0;
		while(n) {
			cin >> str;
			switch(str[1]) {
				case 'I': // HIT
					++base;
					point += base/4;
					base = min(3, base);
					break;
				case 'U': // OUT
					if(++outCount == 3) {
						cout << point << endl;
						point = outCount = base = 0;
						--n;
					}
					break;
				case 'O': // HOMERUN
					point += base + 1;
					base = 0;
					break;
			}
		}
	}
	return 0;
}