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.

**Input:**

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.

**Output:**

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.

**Constraints:**

0<=T<=200

0<=N<1000

**Example:**

**Input:**

4

8

3

0

10

**Output:**

10

7

1

13

**Explanation:**

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.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

jhasaurabh312 | 138 |

Aaaaarohiiii | 136 |

Harsha_kunchala | 128 |

tushki | 124 |

RajaRajput | 117 |

ARUN_PUNDIR | 617 |

manishgupta8497 | 607 |

Abhimanyu_kumar | 559 |

KhyatiSoneji | 501 |

Aman___Jain | 496 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.