#include <iostream>
using namespace std;
char ch[10];
int main(){
	int n,i,oc = 0,point = 0,hc = 0;
	cin >> n;
	for(i=0;i<n;){
		cin >> ch;
		if(ch[0] == 'O'){
			oc++;
		}
		else if(ch[0] == 'H'){
			if(ch[1] == 'O'){
				point += 1 + hc;
				hc = 0;
			}
			else {
				hc++;
				if(hc > 3){
					hc--;
					point++;
				}
			}
		}
		if(oc == 3){
			cout << point << endl;
			point = 0;
			oc = 0;
			hc = 0;
			i++;
		}
	}
	return 0;
}