#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int t;
scanf("%d", &t);
while(t--) {
int a, n;
scanf("%d%d", &n, &a);
int l = 0, r = n, mid, res = -1;
while(l <= r) {
mid = (l + r) / 2;
if((ll)n*a - (ll)mid*(mid+1)/2 >= n-mid) {
res = mid;
l = mid + 1;
} else r = mid - 1;
}
printf("%d\n", res);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwppbnQgbWFpbigpIHsKCWludCB0OwoJc2NhbmYoIiVkIiwgJnQpOwoJd2hpbGUodC0tKSB7CgkJaW50IGEsIG47CgkJc2NhbmYoIiVkJWQiLCAmbiwgJmEpOwoJCWludCBsID0gMCwgciA9IG4sIG1pZCwgcmVzID0gLTE7CgkJd2hpbGUobCA8PSByKSB7CgkJCW1pZCA9IChsICsgcikgLyAyOwoJCQlpZigobGwpbiphIC0gKGxsKW1pZCoobWlkKzEpLzIgPj0gbi1taWQpIHsKCQkJCXJlcyA9IG1pZDsKCQkJCWwgPSBtaWQgKyAxOwoJCQl9IGVsc2UgciA9IG1pZCAtIDE7CgkJfQoJCXByaW50ZigiJWRcbiIsIHJlcyk7Cgl9CglyZXR1cm4gMDsKfQ==