#include using namespace std; /* ショトカ登録 cin cout endl return int double string char pair make_pair first second tuple make_tuple sort erase swap stoi to_string auto bool true false vector queue priority_queue front pop_frpnt size substr push_back pop_back push pop top if for while break continue next_permutation __builtin_popcount */ //無限 int inf = 1020304050; int64_t INF = 1020304050607080900; //モッド int64_t mod = 998244353; //all マクロ #define all(v) v.begin(), v.end() int main () { //少数以下 cout << fixed << setprecision(15); map, int> M; for (int i = 1; i < 40000; i++) { vector l(9, 0); int j = i * i; string s = to_string(j); for (auto x : s) { int k = x - '0'; if (k == 0) continue; l[k - 1]++; } if (M.count(l) == 0) { M[l] = j; } } int TT; cin >> TT; for (int tt = 0; tt < TT; tt++) { int N; cin >> N; string S = to_string(N); vector L(9, 0); for (auto x : S) { int k = x - '0'; if (k == 0) continue; L[k - 1]++; } if (M.count(L) == 0) cout << -1 << endl; else { cout << M.at(L) << endl; } } }