#include <iostream>
#include <cstring>
int main()
{
    using namespace std;
 
    int n;
    cin >> n;
    int ile = 1;
    char wyraz[200];
 
    for (int j = 0; j < n; j++) {
        cin >> wyraz;
        for (int i = 0; i < strlen(wyraz); i++) {
            if (ile <= 2)
                cout << wyraz[i];
            else if (ile >= 3) {
                cout << ile;
                i += ile - 1;
                cout << wyraz[i];
            }
            ile = 1;
            for (int z = i + 1; wyraz[z] == wyraz[i]; z++)
                ile++;
        }
        cout << endl;
    }
 
    return 0;
}