Wandip Base

Dipak's base is being attacked by Chef, and he chooses to hide all his followers by considering their bases as octal and hexadecimal.
He has N followers, all of them can be considered as both octal and hexadecimal numbers.
At first he considers every follower as an octal number (base 8), and then converting to its decimal form and storing it in an array A.
Then, to confuse the Chef even more, Diapk also considers the original N followers as hexadecimal numbers (base 16), and converts these hexadecimal treated numbers into decimal and joins them to the same array A.
Now, Dipak wants to find his friend, whose number corresponds to the Kth smallest entry in the converted array A, but all of them are hiding in decimal formats after being treated as octal and hexadecimal numbers.
Given the number of followers N, and K, help Chef in finding out who his friend is.
Note: Each number is converted to decimal after being treated as an octal and a hexadecimal number. Hence for N numbers, the array will have size 2*N.
Input
First line contains T number of test cases. Every test cases contains 2 lines as follows:
First line of every test case contains 2 numbers N and K.
Second line contains space seperated N numbers.
Output
Output the original number before conversion which corresponds to the Kth smallest entry in the array and the base it was treated as, seperated by a space.
Note: Only if a number has the same decimal representation when treated as octal and hexadecimal, treat the octal number smaller than the hexadecimal number in the sorted array.
Constraints
 1 ≤ T ≤ 10
 8 ≤ N ≤ 10^5
 1 ≤ K ≤ 2*N
 1 ≤ Ai ≤ 10^5 No digits can have digits larger than 7
Example
Input: 1 3 4 11 22 33 Output: 33 8
Explanation
11 ,22 ,33 treated as octal equals 9, 18, 27 in decimal respectively.
11,22,33 treated as hexadecimal equals 17, 34, 51 in decimal respectively.
Thus the final sorted array is: 9,17,18,27,34,51
Thus the 4th smallest entry is 27 => 33 in octal.
Expected output : 33 8
Author:  abizerl123 
Tags  abizerl123 
Date Added:  28022017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, 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, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions