|All-time Popular Problems|
|Sort a stack|
|Delete Middle of Linked List|
|BFS traversal of graph|
|Largest subarray of 0's and 1's|
|Immediate Smaller Element|
|Delete nodes having greater value on right|
|Node at a given index in linked list|
|Two numbers with sum closest to zero|
|Print all nodes that don’t have sibling|
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.