Ozo is making a project on mathematical equation given by his teacher, but he want to test the given equation,
whether this equation contain any positive integral root or not. Because if equation does not contain integral root his project will give abnormal results and he will not able to submit his project on time.

                     Equation:   x^2 = N - Bx

where N is an integer, B is sum of digits of number x. Your task is to find smallest positive integral root of this equation.

INPUT

First line of Input contains no. of test cases T. Each test case contain "N".

OUTPUT

For each test case output smallest positive integral root of the equation or print -1 if there is no positive integral roots.

CONSTRAINTS

T ≤ 10^5

1 ≤ N ≤ 8 * 10^18

SAMPLE INPUT
2
2
4

SAMPLE OUTPUT
1
-1
from sys import stdin;
import math
def dig(u):
	total = 0
	while u:
		total+=u%10
		u/=10
	return total
def sol(u):
	roo = int(math.sqrt(u))
	roo+=1;
	st = 1
	if roo>100:
		st = roo-100
#	print "root is ",roo, " and we start from ",st
	while st<=roo:
		if u%st==0:
			b = st + dig(st)
			if b*st==u:
				return st
		st+=1
	return -1
	


t=int(stdin.readline())
a=stdin.readlines()
for i in xrange(t):
	x=int(a[i])
	print sol(x)