#include<stdio.h>

main(){
	int c,y,t,o,p;
	char a[9];
	scanf("%d",&c);
	for(y=0;;y++){
		t=o=p=0;
		while(~scanf("%s",&a)||exit(1)){
			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);
	}
}