#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
   int t;
   ll a, b, pro;
   ll sq, res = 0;
   cin>>t;
   while (t--) {
      scanf("%lld%lld", &a, &b);
      pro = a * b;
      sq = sqrt(pro);
      res = sq * 2;
       if(sq * sq == pro)
          res = res-2;
       else if((pro - 1) / sq == sq)
           res--;
       if(!(a == b))
           res--;
 		printf("%lld\n", res);
   }
}
