#include <stdio.h>
main()
{
char ch, s[100][256], *p;
int i, n, count;
scanf("%d", &n);
for (i=0; i<n; i++)
{
scanf("%s", s[i]);
}
for (i=0; i<n; i++)
{
p = s[i];
while (*p)
{
count = 1;
ch = *p;
for (++p; *p==ch; p++) count++;
if (count > 1)
printf("%d%c", count, ch);
else
printf("%c", ch);
}
printf("\n");
}
}