using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ0506String
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputDataSets = GetInputData();

            var operatedStrings = OperateStrings(inputDataSets);

            OutputStrings(operatedStrings);
        }

        private static IEnumerable<DataSet> GetInputData()
        {
            var dataSets = new List<DataSet>();
            int operationCount;
            string initialString;

            while(true)
            {
                operationCount = int.Parse(Console.ReadLine());
                if(operationCount == 0)
                {
                    break;
                }

                initialString = Console.ReadLine();
                dataSets.Add(new DataSet(operationCount, initialString));
            }

            return dataSets;
        }

        private static IEnumerable<string> OperateStrings(IEnumerable<DataSet> inputDataSets)
        {
            var operatedStrings = new List<string>();

            foreach (var inputDataSet in inputDataSets)
            {
                var temporaryString = inputDataSet.InitialString;

                for (var i = 0; i < inputDataSet.OperationCount; ++i)
                {
                    temporaryString = OperateString(temporaryString);
                }

                operatedStrings.Add(temporaryString);
            }

            return operatedStrings;
        }

        private static string OperateString(string givenString)
        {
            var operatedString = new StringBuilder();

            const int continuousCountInitialValue = 0;
            var continuousCount = continuousCountInitialValue;
            var previousLetter = givenString.First();

            foreach (var currentLetter in givenString)
            {
                if (!currentLetter.Equals(previousLetter))
                {
                    WriteOutToOperatedString(operatedString, continuousCount, previousLetter);
                    continuousCount = continuousCountInitialValue;
                }

                previousLetter = currentLetter;
                ++continuousCount;
            }

            WriteOutToOperatedString(operatedString, continuousCount, previousLetter);

            return operatedString.ToString();
        }

        private static void WriteOutToOperatedString(StringBuilder operatedString, int continuousCount, char previousLetter)
        {
            operatedString.Append(continuousCount);
            operatedString.Append(previousLetter);
        }

        private static void OutputStrings(IEnumerable<string> operatedStrings)
        {
            foreach (var operatedString in operatedStrings)
            {
                Console.WriteLine(operatedString);
            }
        }

        public class DataSet
        {
            public int OperationCount { get; private set; }
            public string InitialString { get; private set; }

            public DataSet(int operationCount, string initialString)
            {
                this.OperationCount = operationCount;
                this.InitialString = initialString;
            }
        }
    }
}


Measured memory_bytes: 18488