#include <bits/stdc++.h>
using namespace std;
int main(){
int a;
while(a--){
char b,c,d,e,f;
cin >> b >> c >> d >> e;
if(b == c && b == d && b == e){
cout << 0 << endl;
}else if(b != c && b !=d && b != e){
cout << 3 << endl;
}else if((b == c && d == e) || (b == d && c == e) || (b == e && c == d) || (b == c && b == d) || (b == d && b == e) || (b == c && b == d)){
cout << 1 << endl;
}else{
cout << 2 << endl;
}
}
return 0;
}