Brunch Book
Time limit1sMemory limit1024 MB
Given N and K, find the K-th string in the natural (numeric-aware, case-folded) ordering of all N-character hex strings.
- Level
Medium7 of 10
- Topics
- String, Math, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Good writing influences many people, and its value remains intact even when read again years later. "Brunch", operated by Kakao, is a service made for everyone who wants to write well.
Brunch lets you write, edit, and read on every device, so you can record ideas anytime, anywhere, and read beautifully anywhere. You can group the pieces you write by topic or together with other writers who share your interests into a "magazine" and serialize them. By carefully polishing the ideas laid out in a magazine into a "Brunch Book", you can create your own original work, and the Brunch team supports the process of that work being reborn as a book, a lecture, or a new derivative work.
Jongseo, a poet who captivates everyone with both strong programming skills and writing that moves the heart, decided to post his poems on Brunch in line with the latest trend. After reading the writing, Heewon thought it would be good for Jongseo to publish a poetry collection as a Brunch Book, and selected poems. While working on the Brunch Book, Jongseo felt that Heewon had chosen unexpected poems, so they talked it over and found that the title sorting method Heewon's environment used after downloading the poems differed from Jongseo's.
For example, suppose the -th poem of the -th book has a title of the form BookPoem. The -th poem of the -nd book gets the title Book2Poem10, and the -st poem of the -th book gets the title Book10Poem1. The ordinary string comparison used in programming, which Jongseo used, compares from the front and, when differing characters appear, decides the comparison by those characters. Here, at the -th character, where the first difference appears, 2 is greater than 1, so Book2Poem10 is greater than Book10Poem1. But if you know that each poem belongs to the -nd and -th books, it would be natural to compare so that the poem of the -th book is greater.
So Heewon sorted the book titles using the natural string comparison widely used elsewhere. In that string comparison, first all uppercase letters are changed to lowercase. Then consecutive digits are grouped and treated as a number for comparison. Scanning characters from the front, if both sides are digits, the numbers containing those digits are compared; otherwise the two characters are compared. For numbers starting with 0, if the two numbers have the same value, the string with more 0s is smaller. The following is an example of comparing titles using that string comparison: 005a 05ab 5abc 5bcd 006a 6abc 10ab abcd.
On day , Jongseo wrote poems, and each poem's title used, without repetition, all -character strings whose characters each come from 0123456789abcdef. Heewon said that among the poems, the -th poem she liked was the -th poem written on day . What she meant was the -th poem when all titles from day are sorted by natural string comparison, so there were cases where this pointed to a different book than the ordinary string comparison Jongseo used in programming. Jongseo would normally have written a program himself to find the poem titles, but since he wanted to finish the Brunch Book quickly, he asked you to tell him the title of each poem Heewon selected.
Input
The input is given as follows.
- is the number of poems Heewon selected. ()
- and describe the poem Heewon selected. They mean that the -th selected poem is the -th poem when all poems from day are sorted by natural string comparison. (, )
- All numbers in the input are integers.
Output
Output lines in total. On the -th line, output the title of the -th poem Heewon selected.