Aronson's sequence $a_k$ is defined by the self-referential sentence:
"T is the first, fourth, eleventh, ... letter of this sentence."
The blanks (...) are filled in so that the sentence describes itself truthfully. Read the sentence and count only letters (spaces, punctuation, and digits are ignored, and case is ignored). Then $a_k$ is the position of the $k$-th occurrence of the letter T. The first few values are:
$$1,\ 4,\ 11,\ 16,\ 24,\ 29,\ 33,\ 35,\ 39,\ \dots$$
For $k \le 100000$ it can be shown that $a_k \le 1000000$.
To build the sentence you must spell ordinal numbers in English. Ordinals (first, second, third, …) are defined from the cardinals (one, two, three, …), so the cardinals are described first.
3 → three, 17 → seventeen).40 → forty, 56 → fifty six).100 → one hundred, 117 → one hundred seventeen, 640 → six hundred forty, 999 → nine hundred ninety nine).12345 → twelve thousand three hundred forty five).An ordinal is written like its cardinal, but the last word is turned into its ordinal form:
3rd → third, 56th → fifty sixth, 100th → one hundredth, 12345th → twelve thousand three hundred forty fifth.
The input contains several queries. Each query is a positive integer $k$ on its own line ($1 \le k \le 100000$). The queries are given in non-decreasing order. The input ends with a line containing a single 0.
For each query $k$, print $a_k$ on its own line. Every $a_k$ is at most $1000000$.