#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

ll solve(ll, ll);

int main(){
  int q; cin >> q;

  for(int i=0; i<q; i++){
    ll a, b; cin >> a >> b;
    cout << solve(a, b) << endl;
  }

  return 0;
}

ll solve(ll a, ll b){
  ll s = a*b;
  ll sq = (ll)sqrt(s);

  ll ans=0;
  if(sq*(sq+1) < a*b){
    ans += sq*2;
  }
  else{
    sq--;
    ans += sq*2;
    if((sq+1)*(sq+1) < a*b && (sq+1)!=min(a, b)) ans++;
  }

  if(sq >= min(a, b)) ans--;

  return ans;
}
