#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int q;
    cin >> q;
    while(q--){
        ll a, b;
        cin >> a >> b;
        if(a < b) swap(a, b);
        ll right = 1000000007, left = 0;
        while(right - left > 1){
            ll mid = (right + left) / 2;
            if(mid * mid < a * b) left = mid;
            else right = mid;
        }
        ll ans;
        if(left * (left + 1) < a * b) ans = left * 2;
        else ans = left * 2 - 1;
        if(a <= left) ans--;
        if(b <= left) ans--;
        cout << ans << endl;
    }
}
