#include<bits/stdc++.h>
using namespace std;
int main(){
int Q;
  cin>>Q;
  for(int i=0;i<Q;i++){
  int64_t A,B;
    cin>>A>>B;
    int64_t a=min(A,B);
    int64_t b=max(A,B);
    if(a==b)
      cout<<2*a-2<<endl;
    else{
    int64_t c=a*b-1;
    int64_t J=powl(c,0.5);
      if(J*(J+1)<=c)
        J++;
    int64_t ans=J+(c/J)-2;
    cout<<ans<<endl;
    }
  
  
  }
   return 0;
}
