|
<p>David is labelling boxes in a giant warehouse. He has a *lot* of boxes to |
|
label, but unfortunately his labeling machine is broken, so only some of the |
|
letters work. In order to be efficient, David labels the boxes by first using |
|
every possible 1-letter label in alphabetical order, then using every possible |
|
2-letter label in alphabetical order, then every 3-letter label, etc.</p> |
|
|
|
<p>For example, suppose only the letters 'D', 'T', and 'Z' work. David would |
|
label the first 15 boxes as follows: D, T, Z, DD, DT, DZ, TD, TT, TZ, ZD, ZT, |
|
ZZ, DDD, DDT, DDZ. The first box is considered box #1, not box #0.</p> |
|
|
|
<p>Given a set of working letters <strong>L</strong> on David's labelling |
|
machine and a number <strong>N</strong> of boxes to label, return the label on |
|
the last box.</p> |
|
|
|
<h2>Input</h2> |
|
|
|
<p> |
|
The first line of the input consists of a single integer <strong>T</strong>, the number of test |
|
cases. <br /> |
|
Each test case consists of the string <strong>L</strong> and the integer <strong>N</strong>, separated by a space. </p> |
|
|
|
<h2>Output</h2> |
|
<p> |
|
For each test case <strong>i</strong> numbered from 1 to <strong>T</strong>, output "Case #<strong>i</strong>: ", followed by the label on the last box.</p> |
|
|
|
<h2>Constraints</h2> |
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 20 <br /> |
|
1 ≤ length(<strong>L</strong>) ≤ 25 <br /> |
|
<strong>L</strong> will be in alphabetical order, consist of only uppercase letters A-Z, and contain each letter at most once <br /> |
|
1 ≤ <strong>N</strong> ≤ 2<sup>63</sup>-1 <br /> |
|
The test cases will be designed so that no label is longer than 50 letters<br /> |
|
</p> |
|
|
|
|