#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

#include<vector>

#define INF 999999
using namespace std;
int main(){
    int N;
    cin>>N;
    while(N--){
        int score=0,hitcnt=0;
        string sum;
        for(int out=0;out!=3;){
            cin>>sum;
            if(sum[0]=='O')out++;
            else if(sum[0]=='H'&&sum[1]=='I'){
                if(hitcnt==3)score++;
                else hitcnt++;
            }
            else{
                score+=hitcnt+1;
                hitcnt=0;
            }
        }
        cout<<score<<endl;
    }
    return 0;
}