# Compression - version Python 3 def run_length_encoding(): t = int(input()) # nombre de testcases for _ in range(t): s = input() i = 0 while i < len(s): j = i while j < len(s) and s[j] == s[i]: j += 1 print(f"{j - i}{s[i]}", end="") i = j print() # Exécution if __name__ == "__main__": run_length_encoding()