#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; } map mp; void solve() { string N; cin >> N; while(N.size() < 10) N += '0'; sort(N.begin(), N.end()); if(mp.count(N)) cout << mp[N] << endl; else cout << -1 << endl; return; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); for(int i=1; i*i<=1'000'000'000; ++i) { int y = i*i; string x = to_string(y); while(x.size() < 10) x += '0'; sort(x.begin(), x.end()); if(!mp.count(x)) mp[x] = y; } int T; cin >> T; for(int i=0; i