Palindrome Magic

In MathWorld, each student is issued a unique ID which is a palindromic number. This ensures that the students can easily remember their ID. But the administration is afraid of a problem. It is afraid that if it keeps a very small ID, then it may soon run out of unique palindrome numbers. Thus, it has hired you as they've run out of mathematicians and programmers. So, they tell you the problem and then ask you to solve the following problem.
For a ndigit palindrome, what is the kth palindrome (if arranged in ascending order) that can be formed?
For eg. In the list of 2 digit palindromes, the 7th palindrome is 77 (1st being 11, 2nd being 22 and so on).
The input will be of the form of an ordered pair n,k where n<=9. Find the kth ndigit palindrome.
Note: This problem is pretty elementary to such an expereinced person as you, and so the administration asks you to solve it as fast as possible, so try and minimize the running time of your code as much as possible.
Input
The first line of the input contains T, the number of test cases that follow. The following T lines contain two values separated by a space. The first one is n (number of digits in the palindrome) and the next is k (the kth number in ascending order to be found)
Output
The output should be of T lines, where each line has the corresponding output of the test case. That is line 2 will contain kth ndigit palindrome for the 2nd test case.
Example
Input: 3 4,9 7,50 9,120 Output: 1881 1049401 101191101
Author:  rajatkhanduja 
Tags  rajatkhanduja 
Date Added:  7082012 
Time Limit:  0.1465 sec 
Source Limit:  50000 Bytes 
Languages:  C, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions