#include using namespace std; using ll = long long; int main() { int Q; cin >> Q; while(Q--) { ll A, B; cin >> A >> B; ll P(max((ll)(sqrt(4LL*A*B)-30LL), 0LL)); while(!(4*A*B < P * P)) { P++; } ll X(max((ll)(sqrt(P+A+B)-30LL), 0LL)); while((X * X - A - B) < 0) X++; while(!(4*A*B < (X * X - A - B) * (X * X - A - B))) { X++; } cout << X << endl; } return 0; }