#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(int argc, char **argv) {
int T;
scanf("%d", &T);
while (T-- != 0) {
ll n, a;
scanf("%lld%lld", &n, &a);
ll tot = 2 * n * (a - 1), lo = 0, hi = n - 1;
while (lo < hi) {
ll mid = (lo + hi + 1) / 2;
if (mid * (mid + 1) <= tot)
lo = mid;
else
hi = mid - 1;
}
printf("%lld\n", lo + 1);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmludCBtYWluKGludCBhcmdjLCBjaGFyICoqYXJndikgewoJaW50IFQ7CglzY2FuZigiJWQiLCAmVCk7Cgl3aGlsZSAoVC0tICE9IDApIHsKCQlsbCBuLCBhOwoJCXNjYW5mKCIlbGxkJWxsZCIsICZuLCAmYSk7CgkJbGwgdG90ID0gMiAqIG4gKiAoYSAtIDEpLCBsbyA9IDAsIGhpID0gbiAtIDE7CgkJd2hpbGUgKGxvIDwgaGkpIHsKCQkJbGwgbWlkID0gKGxvICsgaGkgKyAxKSAvIDI7CgkJCWlmIChtaWQgKiAobWlkICsgMSkgPD0gdG90KQoJCQkJbG8gPSBtaWQ7CgkJCWVsc2UKCQkJCWhpID0gbWlkIC0gMTsKCQl9CgkJcHJpbnRmKCIlbGxkXG4iLCBsbyArIDEpOwoJfQoJcmV0dXJuIDA7Cn0=