1a~~哇咔咔!!
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 18;
i64 wp[maxn];
i64 n;
i64 ans;
int a[maxn];
int len;
void find(i64 now=0,int step=0)
{
if(step == len)
{
ans = min(ans,now);
}
else
{
i64 temp,to;
for(int i=0;i<=9;i++)
{
to = temp = now+wp[step]*i;
temp*=temp;
temp/=wp[step];
temp%=10;
if(temp==a[step])
{
find(to,step+1);
}
}
}
return ;
}
void start()
{
i64 temp = n;
len = 0;
MM(a,0);
while(temp)
{
a[len++]=temp%10;
temp/=10;
}
ans = inf64;
find();
return ;
}
void init()
{
wp[0]=1;
for(int i=1;i<maxn;i++)
{
wp[i]=wp[i-1]*10;
}
return ;
}
int main()
{
init();
int T;
cin>>T;
while(T--)
{
cin>>n;
start();
if(ans==inf64)
{
cout<<"None"<<endl;
}
else
{
cout<<ans<<endl;
}
}
return 0;
}