#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll q;
  cin >> q;
  while(q--) {
    ll a,b;
    cin >> a >> b;
    if(b<a) {
      a+=b;
      b=a-b;
      a=a-b;
    }
    ll c=sqrt(a*b);
    if(a!=b) {
      ll ans=2*c-3;
      if(c*c<a*b) ans++;
      if(c*(c+1)<a*b) ans++;
      cout << ans << endl;
    }
    else cout << 2*(c-1) << endl;
  }
}