#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define se second
#define fi first
#define pb push_back
#define pf push_front
using namespace std;
long double rad = 57.295779513, pi = 3.1415926535;
int mod = 1000000007;
const int N = 4e5 + 17;
ll n , i , j;
string s;
void solve(){
//UwU
cin >> s;
sort(s.begin() , s.end());
if(s[0] == s[3]){
cout << -1;
return ;
}
int p = 0;
for(i = 1;i < 4; ++ i){
if(s[i] != s[i - 1]) p ++;
}
if(p + 1 == 2 and (s[0] != s[1] or s[2] != s[3])) cout << 6;
else cout << 4;
}
main()
{
//cout << v.size();
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
ll T = 1;
cin >> T;
while(T --)
{
solve();
cout << '\n';
}
}
//anro
//musoxon
//#NOWAR
//atso city and yes this is city
//
Lift queries | Goki and his breakup |
Ali and Helping innocent people | Book of Potion making |
Duration | Birthday Party |
e-maze-in | Bricks Game |
Char Sum | Two Strings |
Anagrams | Prime Number |
Lexical Sorting Reloaded | 1514A - Perfectly Imperfect Array |
580A- Kefa and First Steps | 1472B- Fair Division |
996A - Hit the Lottery | MSNSADM1 Football |
MATCHES Playing with Matches | HRDSEQ Hard Sequence |
DRCHEF Doctor Chef | 559. Maximum Depth of N-ary Tree |
821. Shortest Distance to a Character | 1441. Build an Array With Stack Operations |
1356. Sort Integers by The Number of 1 Bits | 922. Sort Array By Parity II |
344. Reverse String | 1047. Remove All Adjacent Duplicates In String |
977. Squares of a Sorted Array | 852. Peak Index in a Mountain Array |