You are given an integer n, find the smallest positive integer root of equation x, or else print -1 if no roots are found.

Equation: x^2+s(x)*x-n=0

where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.

**Input: **

First line of input contains a single integer T denoting the number of test cases. First line of every test case has one number N.

**Output:**

For each test case, print the smallest positive integer root of equation x, or else print -1 if no roots are found.

**Constraints: **

1 <= T <= 100

1 <= N <= 10^{18}

**Example: **

**Input: **

1

110

**Output:**

10

**Explanation:**

In the above test case x=10 is the minimum root. As s(10)=1+0=1 and 102+1*10-110=0.

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.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

devsinghindra | 80 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 443 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.