#include //#include using namespace std; //using namespace atcoder; typedef long long ll; typedef long double ld; #define sz(c) ((ll)(c).size()) #define ALL(x) x.begin(),x.end() #define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin()) #define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin()) #define BS(A,x) binary_search(ALL(A),x) #define rep(i,a,b) for(int i=a;ibool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } using vi = vector; using vvi = vector; using vl =vector; using vvl=vector; const long long mod=998244353; //using mint = modint998244353; int main() { mapmp; for(ll i=1;i*i<1e10;i++){ vi A; ll N=i*i; while(N){A.push_back(N%10);N/=10;} sort(ALL(A)); reverse(ALL(A)); //while(A.back()==0)A.pop_back(); if(mp[A]==0)mp[A]=i*i; } int tt;cin>>tt; while(tt--){ ll n;cin>>n; vi B; while(n){B.push_back(n%10);n/=10;} sort(ALL(B)); reverse(ALL(B)); //while(B.back()==0)B.pop_back(); //rep(i,0,sz(B))cout<