#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
cin >> n;
while (n -- )
{
string str;
int num = 1;
cin >> str;
for (int i = 0; i < str.size(); i ++ )
{
if (str[i] == str[i + 1]) num ++ ;
else
{
if (num == 1)
{
cout << str[i];
num = 1;
}
else
{
cout << num << str[i];
num = 1;
}
}
}
cout << endl;
}
return 0;
}