An Interesting Set
Time Limit: 1000 mSec
Memory Limit: 32768 KB
Thomas, a mathematician, is interested in a set S consisting of positive integers. Set S is defined as follows:
(1) If a positive integer satisfies the property that the sum of all digits of it is equal to the product of them, then it belongs to S.
(2) If m belongs to S, then 2m belongs to S.
Thomas wants to find out the Kth smallest integer in set S. Design a program to solve the problem.
The first line in the input is an integer N representing the number of test cases. The following N lines are N test cases and each line contains an integer K (1<=K<=500).
For each test case, output a line containing an integer that is the Kth smallest integer in set S.