#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
ll k,x,x1,x2,x3,x4;
int main()
{
scanf("%lld",&k);
while(k--)
{
ll l=1,r=2e9,mid,res=0;
scanf("%lld",&x);
while(l<r)
{
//cout<<++res<<" "<<l<<" "<<r<<endl;
mid = l+r>>1;
if(mid*2*mid-mid> x) r=mid;
else l=mid+1;
}
ll s;
if(l>r)
{
s=r;
r=l;
l=s;
}
if(l==r) l=r-1;
x1=l*2*l-l+1;
x2=l*2*l-l+r-1+1;
x3=l*2*l-l+(r-1)*3+1;
x4=l*2*l-l+(r-1)*4+1;
if(x>=x1&&x<x2) res=x-x1;
else if (x>=x2&&x<x3) res = r-1-(x-x2);
else res = -(x4-x);
if(x==1) res=0;
printf("%lld\n",res);
}
}