#include using namespace std; using ll = long long; bool f(ll X, ll A, ll B){ if (X*X-A-B <= 0) return 0; if (X*X-A-B > 3e9) return 1; return A*B*4 < (X*X-A-B) * (X*X-A-B); } void solve(){ ll A, B; cin >> A >> B; ll l=0, r=1e9, c; while(r-l>1){ c = (l+r)/2; if (f(c, A, B)) r=c; else l=c; } cout << r << endl; } int main(){ int N; cin >> N; while(N){ N--; solve(); } return 0; }