#include<iostream>
#include<cmath>
using namespace std;
#define df 0
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int q; cin >>q;
  for(int i=0;i<q;i++){
    li a,b; cin >>a >>b;
    if(a==b){
      printf("%d\n",2*(a-1));
      continue;
    }
    if(a>b)swap(a,b);
    li sq=sqrt(a*b);
    int d=(a*b-1)/sq;
    printf("%ld\n",sq+d-2);
  }
}

/// confirm df==0 ///
