K - DICTIONARY

3

4 votes
Basics of bit manipulation
Problem

Sheldon has come up with a new language in which all words are made up of exactly K Lowercase english Letters .

For example if K=4, then :

  • words "aaaa", "abcc", "zdsa" belong to the language as they are made up of exactly 4 Lowercase english letters
  • words "aa", "abbbb", "abccc" don't belong as they are not made up of exactly 4 letters
  • words "Abcd", "aabD" don't belong as letters 'A' and 'D' are not lowercase.

Now consider a K-dictionary that contains all the words of this new language in asscending order.  For example if K=3, the dictionary contains words "aaa", "aab", "aac" ... "aaz", "aba", "abb" ...  "abz", "aca" and so on.

Sheldon wants to translate "The roommate agreement" into this new language. The translation is done word by word as follows :

  • If a word has position P is the "Oxford English Dictionary", it translates to the word with position P in the K-dictionary.
  • For example if K=3, and a word has position 4 in the "Oxford English Dictionary", it translates to "aad".

Clearly the above translation is a complex process and can't be done manually. So Sheldon asked his friend Howard for help. But as Sheldon always makes fun of him, Howard refused. So now you have to help Sheldon.

More formally you will be given two integers K and P, You have to find the word with position P in the K-dictionary. You have to do this for T test cases.


Input : 

  • First line of input contains T, denoting number of Test cases.
  • First line of every test case contains two integers K and P.

Output :

For every test case print the word with position P in K-dictionary. If P exceeds the size of the K-dictionary, print 1.

Answer of every test case should start in a seperate line.


Constraints :

  • 1T105
  • 1K5105, Sum of K over all test cases does not exceed 5105
  • 1P1018

Subtasks : 

10 points :

  • T=1
  • 1K4

90 points :

  • Original constraints

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For K=4, dictionary contains words in order : "aaaa", "aaab", "aaac", "aaad", "aaae" .. and so on. The word at 4th position is "aaad". So output for K=4,P=4 is "aaad"

For K=1, there are only 26 words "a", "b", ... "z" in the dictionary. So output for K=1,P=30 is 1

Editor Image

?