#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

int loop;
int HIT,OUT,point;
string stait;
int main(){
  scanf("%d",&loop);
  for(int i=0;i<loop;i++){
    int base[4]={0};
    point = 0;
    OUT=0;
      while(OUT<3){
	cin>>stait;
	cout<<stait[1];
	if(stait[1]=="O"){
	  for(int j=1;j<4;j++)
	    if(base[j]==1){base[j]=0;point++;}
	  point++;
	}
	if(stait[1]=="U"){OUT++;}
	if(stait[1]=="I"){
	  if(base[3]==1){
	    point++;
	  }
	  for(int j=3;j>1;j--){
	    base[j]=base[j-1];
	    base[j-1]=0;
	  }
	}
      }
      printf("%d\n",point);
  }
}