#include <iostream>
using namespace std;
/*
string int_to_string(int liczba)
{
string zwracany;
if(liczba<10)
zwracany = char(liczba+48);
else if(liczba>=10 && liczba<100)
{
string pomocniczy;
zwracany = char(((liczba/10)%10)+48);
pomocniczy = char((liczba%10)+48);
zwracany += pomocniczy;
}
else if(liczba>=100 && liczba<1000)
{
string pomocniczy, pomocniczy2;
zwracany = char(((liczba/100)%10)+48);
pomocniczy2 = char(((liczba/10)%10)+48);
pomocniczy = char((liczba%10)+48);
zwracany = zwracany + pomocniczy2 + pomocniczy;
}
else
{
return "Jestesmy poza zakresem funkcji...";
}
return zwracany;
}
*/
int main()
{
int testAmount;
cin>>testAmount;
string slowa[testAmount];
for(int a = 0 ; a<testAmount ; a++)
{
//cin.clear();
//cin.sync();
cin>>slowa[a];
size_t found = string::npos, found2 = string::npos, found3 = string::npos;
int licznik;
for(int i = 65 ; i<91 ; i++)
{
found = string::npos; found2 = string::npos; found3 = string::npos;
licznik = 0;
found = slowa[a].find(char(i));
if(found!=string::npos)
{
found2 = found;
licznik++;
while(found!=string::npos)
{
found3 = found;
found = slowa[a].find(char(i), found+1);
if(found!=string::npos && found3==(found-1))
{
licznik++;
}
else
{
if(licznik>2)
{
slowa[a].erase(found2+1,licznik-1);
slowa[a].insert(found2+1,to_string(licznik));
}
licznik = 0;
found2 = slowa[a].find(char(i), found2+2);
if(found2!=string::npos) {licznik++; found = found2;}
}
}
}
}
}
for(int i = 0 ; i<testAmount ; i++)
cout<<slowa[i]<<endl;
return 0;
}