Number That Count

No attempts yetTime limit1sMemory limit128 MB

Problem

"Kronecker's Knumbers" is a small company that makes plastic digits for signs, the kind used on theater marquees and gas station price displays. The owner and sole employee, Klyde Kronecker, records how many of each digit he has used in an inventory book. Say he has just finished a sign carrying the telephone number "5553141". In one column he writes 5553141, and in the next he lists the digits he used: two 1s, one 3, one 4, and three 5s. Digits he did not use never appear. He writes this in condensed form as 21131435.

The other day Klyde filled an order for 31123314 and found that the inventory of this number is the number itself: three 1s, one 2, three 3s, and one 4. He calls such a number self-inventorying. He wants to know which numbers are self-inventorying, and which ones reach a self-inventorying number by repeating the inventory operation defined below.

Given a non-negative integer nn, its inventory is the integer formed by concatenating c1d1c2d2ckdkc_1 d_1 c_2 d_2 \cdots c_k d_k, where every cic_i is a positive integer, every did_i is a digit, and 0d1<d2<<dk90 \le d_1 < d_2 < \cdots < d_k \le 9. For each digit dd that appears in nn there is an ii with d=did = d_i, and that dd occurs exactly cic_i times in the decimal representation of nn. For 5553141 we set c1=2c_1 = 2, d1=1d_1 = 1, c2=1c_2 = 1, d2=3d_2 = 3, and so on, giving 21131435. The inventory of 1000000000000 is 12011, twelve 0s and one 1.

nn is self-inventorying if nn equals its own inventory. It becomes self-inventorying after jj steps if jj (j1j \ge 1) is the smallest number for which the jj-th iterated inventory of nn is self-inventorying. The inventory of 21221314 is 31321314, the inventory of 31321314 is 31123314, and 31123314 is self-inventorying, so 21221314 becomes self-inventorying after 2 steps.

nn enters an inventory loop of length kk if kk (k2k \ge 2) is the smallest number for which the jj-th iterated inventory equals the (j+k)(j + k)-th iterated inventory for some j0j \ge 0. The inventory of 314213241519 is 412223241519, and the inventory of 412223241519 is 314213241519 again, so 314213241519 enters an inventory loop of length 2, with j=0j = 0.

Write a program that reads a sequence of non-negative integers and, for each value, reports whether it is self-inventorying, becomes self-inventorying after jj steps, enters an inventory loop of length kk, or fits none of these after 15 applications of the inventory operation.

Input

The input gives one non-negative integer per line. Each integer has at most 80 digits and no extra leading zeros. The last line holds the terminating value -1, which is not part of the data.

Output

For each input value nn, print exactly one of the four lines below. Echo nn exactly as it appears in the input. jj is a positive integer and kk is an integer greater than 1.

n is self-inventorying
n becomes self-inventorying after j steps
n enters an inventory loop of length k
n can not be classified after 15 iterations

The inventory operation is applied at most 15 times, so only n0=nn_0 = n through n15n_{15} are examined. If none of the first three conditions shows up among those values, print the fourth line. The word steps is used even when j=1j = 1.