#include typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; #define mp make_pair #define pb push_back #define bp __builtin_popcount #define mt(a,b,c) mp(a,mp(b,c)) const ll mo=1e9+7; const ll INF=1e9; const ld pi=acos(-1); const int mxn=1e4+5; const int cons=1; using namespace std; int main() { //freopen("input.txt","r",stdin); ios_base::sync_with_stdio(false); cin.tie(NULL); ll q,l,c,n,a,temp,i,ad; cin>>q; while(q--) { cin>>n>>c; a=-1; l=0; while(2*l<=n) { temp=( (n-2*l)*(n-2*l-1) )/2; if(temp==c) { a=l; break; } else if(temp