My approach was rather different. It is more complicated, but fast for large N in that the time of solution does not increase with N.
First note that a typical solution may be divided into 3 parts: (1) leading 1s, (2) some digits 2 to 8 non-descending order, (3) trailing 9s. Not all of these parts are present in all solutions.
Start by considering all 1s. Evaluate the extra required K to bring it up to the next perfect square. If the extra required exceeds some number M, add enough 9s to the end of the solution to bring K down below M. For each 9 added, K is reduced by 80 = 9^2 – 1^2, so the required number of 9s is the result of a direct calculation.
Look up in a pre-calculated array what the solution is for this K, if any. Then try the next perfect square, in case this leads to a smaller solution overall. Continue trying each perfect square in turn until we are sure that no solution better than the present one can be found.
The question then remains as to how large the pre-calculated array needs to be. By experiment I found that the largest value of K such that
Solution[k] < Solution[k-80] is 252. It is therefore sufficient to set M = 320 (next multiple of 80), as there is no benefit in having a larger number. Further experimentation shows that the maximum number of digits 2 to 8 in any solution is only 6, so it is sufficient for the array to contain numbers with 10 digits, that is 6 as found here plus up to 3 trailing 9s plus 1 to allow comparison of solutions with different number of trailing 9s. The only values of K for which there is no solution are less than 14, so a solution can always be found by going to a larger number. Evaluating this array is the slowest part of the whole algorithm, taking about 0.01 seconds, but it only needs to be done once. It might be possible to reduce the number of digits stored and M, but I am not sure.
All possible solutions are stored as arrays of decimal digits, making it easy to work with digits.
The algorithm described here could happily cope with 100 or maybe even 1000 test cases within the time limit, although it might take too long to print all the digits. Printing the last 50 or so digits would be enough to identify whether a solution is correct, as all earlier digits are 1s.
You can see my solution at CodeChef: Practical coding for everyone