#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(4*A*B)-10), 0LL)); while(!(4*A*B < P * P)) { P++; } ll X(max((ll)(sqrt(P+A+B)-10), 0LL)); while(!(4*A*B < (X * X - A - B) * (X * X - A - B))) { X++; } cout << X << endl; } return 0; }