#include using namespace std; using ll = long long; bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; } bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; } void solve(map &mp) { string N; cin >> N; int ans = 2'000'000'000; sort(N.begin(), N.end(), greater()); while(N.size() > 0) { if(N.back() == '0') N.pop_back(); else break; } while(N.size() < 10) { if(mp.count(N)) chmin(ans, mp[N]); N += '0'; } if(ans == 2'000'000'000) cout << -1 << endl; else cout << ans << endl; return; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); map mp; for(int i=1; i*i<=1'000'000'000; ++i) { int y = i*i; string x = to_string(y); sort(x.begin(), x.end(), greater()); if(!mp.count(x)) mp[x] = y; } int T; cin >> T; for(int i=0; i