#include "stdio.h" #include "tuple" #include "algorithm" using namespace std; char str[100001]; char cand1[100000], cand2[100001]; int main() { int T; scanf("%d", &T); while(T--) { scanf("%s", str); tuple frequencies[256]; int len = 0; for(int i=0; str[len=i]; i++) { get<1>(frequencies[(int)str[i]]) = str[i]; get<0>(frequencies[(int)str[i]])++; } sort(frequencies, frequencies+256); int max = get<0>(frequencies[255]); if(max+max>len+1) { printf("-1\n"); continue; } int top = len/2; for(int i=0, count=0; i<256; i++) { char c = get<1>(frequencies[i]); int num = get<0>(frequencies[i]); while(num--) { if(count