#include<stdio.h>

int main(){
	int c,y,t,o,p;
	char a[9];
	for(y=0;y<c;y++){
		for(t=o=p=0;;){
			if(!~scanf("%s",a))return 0;
			if(a[0]=='H')t++;
			else o++;
			if(a[1]=='O'){p+=t;t=0;}
			if(t>3){p++;t--;}
			if(o>2)break;
		}
		printf("%d\n",p);
	}
}