#include #include #include #include #include #include #define IOS ios::sync_with_stdio(false) using namespace std; #define inf (0x3f3f3f3f) typedef long long int LL; #include #include #include #include #include #include #include #include int calc_min(int val) { if (val == 1) return 0; if (val == 2) return 1; return 2 * (val - 2); } void work() { int len, c; cin >> len >> c; if (1LL * len * (len - 1) / 2 < c || c < calc_min(len)) { cout << "-1" << endl; return; } } int main() { #ifdef local freopen("data.txt", "r", stdin); // freopen("data.txt", "w", stdout); #endif IOS; int t; cin >> t; while (t--) work(); return 0; }