#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(a>b) {
      ll tmp=a;
      a=b;
      b=tmp;
    }
    ll c=sqrtl(a*b-1);
    ll ans=2*c;
    if(a<=c) ans--;
    if(c*(c+1)>=a*b) ans--;
    cout << ans << endl;
  }
}