#include <iostream>
#include <sstream>
using namespace std;
string intToStringConversion(int number)
{
ostringstream ss;
ss << number;
string str = ss.str();
return str;
}
int countApperancesOfChosenSign (string word, int position)
{
int occurencesNumber = 1;
if (word.length() > position)
{
while (word[position] == word[position + 1])
{
occurencesNumber++;
position++;
}
}
else
occurencesNumber = 0;
return occurencesNumber;
}
string wordShortening (string shortenWord)
{
int wordLength = shortenWord.length();
int occurencesNumber;
char repeatedSign;
for ( int i = 0; i < wordLength - 2; i++ )
{
if ((shortenWord[i] == shortenWord[i + 1]) && (shortenWord[i + 1] == shortenWord[i + 2]))
{
occurencesNumber = countApperancesOfChosenSign (shortenWord, i);
repeatedSign = shortenWord[i];
shortenWord.replace(i, occurencesNumber, repeatedSign + intToStringConversion(occurencesNumber));
wordLength = shortenWord.length();
}
}
return shortenWord;
}
int main()
{
int howManyTests;
string word;
cin >> howManyTests;
for (int i =0; i < howManyTests; i++)
{
cin >> word;
cout << wordShortening (word) << endl;
}
return 0;
}