/*CODED BY mahmudulsakib2019
DATE:-12/03/2024;TIME:-16:10 pm
BANGALDESH , SYLHET*/
#include <iostream>
#include <cmath> ///mathematics
#include<cstdlib> ///for std::exit(EXIT_SUCCESS)
#include <vector> ///array
#include <regex> ///searching_prefix_suffix
#include <algorithm> ///finding_max_min_from_array
#include <string> ///string_manipulation
#include <numeric> ///findin total sum of an array
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
bool square(ll num){
ll root = round(sqrt(num));
return num == root*root;
}
int main() {
int t;
cin >> t;
while(t--)
{
ll B,D;
cin >> B ;
vector<ll>p;
for(ll i =1;i<=(B*B)/2;i++){
ll c =(i*i)+(B*B);
ll C=round(sqrt(c));
if(square(c)){
D = B+i+C;
p.push_back(D);
}
}
if(p.empty()){
cout << -1 << endl;
}else{
auto it = max_element(p.begin(),p.end());
cout << *it << endl;
}
}
return 0;
}