|All-time Popular Problems|
|Check if subtree|
|Delete Middle of Linked List|
|Given a linked list of 0s, 1s and 2s, sort it.|
|Count nodes of linked list|
|Delete N nodes after M nodes of a linked list|
|Check for Balanced Tree|
|Remove every k'th node|
|k largest elements|
|0 - 1 Knapsack Problem|
|Subarray with given sum|
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps where in each step number is replaced by sum of squares of its digit that is if we start with Happy Number and keep replacing it with digits square sum, we reach 1.
First line of input is an integer T, denoting the number of test cases. For each test case, there is one line of input consisting of an integer N, whose next smallest happy number has to be found.
The only line of output for each test case consists of the next smallest happy number for the given number N. If the integer N, is a happy number itself, then too, it's next smallest happy number should be printed as output.
The next smallest happy numbers for the numbers 8,3 and 0 are 10,7 and 1 respectively. For 10 which is a happy number itself, therefore it's next smallest happy number is 13.