#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
while(n--){
getchar();
for(int i=0;i<4;i++){
char c,ans;
cin>>c;
getchar();
cin>>ans;
if(ans=='T'){
cout<<c-'A'+1;
}
}
}
return 0;
}