Blue Gene, Jr.

No attempts yetTime limit1sMemory limit128 MB

Problem

Inspired by IBM's Blue Gene project, the CEO of Universal Biological Machinery (UBM) has called on you, UBM's top software engineer. The company's privately subsidized space program found a virus on Mars, the Areopagusvirus, and you have to write a program that calculates how it mutates.

Input

The input is a non-empty series of up to 100 data sets. Each data set follows the description below, and no blank lines separate the data sets.

A single data set has three parts.

  1. Start line: a single line START N, where 1N201 \le N \le 20.
  2. Viral code: a single line of NN alphanumeric characters. An alphanumeric character is an uppercase letter A to Z, or a digit 0 to 9.
  3. End line: a single line END.

A single line ENDOFINPUT follows the final data set.

Output

For each data set there is exactly one output set, and no blank lines separate the output sets.

A single output set is one line holding the viral code after it has stabilized through mutating. The viral code mutates according to the following rules.

  1. The first viral segment to mutate begins with the first alphanumeric character of the viral code and ends with the rightmost alphanumeric character of the code.
  2. If the first alphanumeric character of a viral segment is a letter, that character is unstable, and it mutates into nn, the number of mutations that occur in the viral segment immediately to its right (see rule 5). If nn is greater than 9, the character mutates into the remainder of nn divided by 10. If there is no viral segment immediately to the right of the unstable character, it mutates into 0.
  3. If the first alphanumeric character of a viral segment is a digit nn from 1 to 9, that character is also unstable, and it mutates into n1n-1. It also makes the viral segment that begins with the alphanumeric character nn positions to its right and ends with the rightmost alphanumeric character of the viral code mutate. If there is no alphanumeric character nn positions to its right, then the viral segment immediately to its right (see rule 5) mutates, if one exists.
  4. If the first alphanumeric character of a viral segment is 0, that character is stable and does not mutate. The character stays 0, and no mutation is counted.
  5. The viral segment immediately to the right of an alphanumeric character begins with the alphanumeric character one position to its right and ends with the rightmost alphanumeric character of the viral code.