#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); using arr = array; map mp; for (int i = 1; i * i <= 1'000'000'000; ++i) { int x = i * i; string s = to_string(x); arr a = { 0 }; for (char c : s) { if (c == '0') continue; a[c - '1']++; } if (!mp.contains(a)) mp[a] = x; } int q; cin >> q; while (q--) { string s; cin >> s; arr a = { 0 }; for (char c : s) { if (c == '0') continue; a[c - '1']++; } if (mp.contains(a)) { cout << mp[a] << '\n'; } else { cout << -1 << '\n'; } } return 0; }