#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
int main(){
  ll q;cin>>q;
  rep(i,q){
    ll x,y;
    cin>>x>>y;
    if(x>y)swap(x,y);
    ll ans=x-1;
    long double k=sqrt(x*y-0.75)-x+0.5;
    ll lk=k;
    ans+=k+(x*y-1)/(x+k);
    if(x==y)cout<<ans<<endl;
    else cout<<ans-1<<endl;
  }
}
