#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    long long int x,y,num,ans,n;
    cin >> n;
    while(n--){
        cin >> x >> y;
        num = sqrt(x*y);
        if( sqrt(x*y)==num ){
            num*=2;
            if(x==y)    num++;
            cout << num-3 << endl;
        }
        else{
            ans = num;
            ans*=2;
            if(num*(num+1) < x*y)   ans++;
            cout << ans-2 << endl;
        }
    }
}