#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
int Q; cin >> Q;
for(int i=0; i<Q; i++){
    ll A, B; cin >> A >> B ;
    ll C=min(A,B); ll D=max(A,B);
    ll ans=0;
    ll E = floor(sqrt( (long double)C*D ) );
    if(C==D) ans=2*(C-1);
    else if(E*E==C*D) ans = 2*(E-1)-1;
    else{
        if(E*(E+1) <C*D ){
            ans = 2*E-1;
        }
        else{
            ans = 2*E-2;
        }
    }
    cout << ans << endl;
}
}