#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[20],b[20],sa[20],sb[20];
void work()
{
int ans = 5;
for(int i = ‘A‘; i <= ‘D‘; i++){
for(int j = 1; j <= 10; j++){
for(int k = 1; k <= 5; k++){
sa[k] = i;
sb[k] = j + k - 1;
if(sb[k] == 14) sb[k] = 1;
}
int res = 5;
for(int k = 1; k <= 5; k++){
for(int l = 1; l <= 5; l++){
if(a[k] == sa[l] && b[k] == sb[l])
res--;
}
}
if(res < ans) ans = res;
}
}
printf("%d\n",ans);
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
for(int i = 1; i <= 5; i++){
scanf(" %c%d",&a[i],&b[i]);
}
work();
}
return 0;
}