#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll calc(ll a, ll b){
  ll x = a*b;
  // isqrt
  ll low = 0, high = MOD;
  while(low+1<high){
    ll m = (low+high)/2;
    if(m*m<=x){
      low = m;
    }else{
      high = m;
    }
  }
  ll isq = low;
  ll ans = 0;
  if(isq==0){
    ans = 0;
  }else if(isq*isq==x){
    if(isq==a && isq==b){
      ans = 2ll*(isq-1ll);
    }else{
      ans = 2ll*(isq-1ll) -1ll;
    }
  }else if(isq*(isq+1ll)<x){
    ans = 2ll*isq - 1ll;
  }else{
    ans = 2ll*isq - 2ll;
  }
  return ans;
}

static const ll INF = 1000000000000000ll;

#define MAX_V 10010
// Dinic http://www.prefield.com/algorithm/graph/dinic.html
struct dinic{
  struct edge{int to;ll cost;};
  int n;
  vector< vector<edge> > G;
  vector<vl> flow, capacity;
  #define RESIDUE(s,t) (capacity[s][t]-flow[s][t])
  vi level;
  vector<bool> finished;
  dinic(int _n){
    n = _n;
    G.assign(n,vector<edge>());
    flow.assign(n,vl(n,0));
    capacity.assign(n,vl(n,0));
    level.assign(n,0);
    finished.assign(n,false);
  }
  void add_edge(int from,int to,ll cost){
    assert(0<=from && from<n);
    assert(0<=to && to<n);
    G[from].push_back((edge){to,cost});
    G[to].push_back((edge){from,0ll});  // 逆に流すフローのためのダミー辺
  }
  ll dfs(int u, int t, ll cur){
    if(u==t || cur==0) return cur;
    if(finished[u]) return 0;
    finished[u] = true;
    REP(i,G[u].size()){
      edge e = G[u][i];
      if(level[e.to] > level[u]){
        ll f = dfs(e.to, t, min(cur, RESIDUE(u,e.to)));
        if(f>0){
          flow[u][e.to] += f;
          flow[e.to][u] -= f;
          finished[u] = false;
          return f;
        }
      }
    }
    return 0;
  }
  ll calc(int s, int t){
    REP(i,n)REP(j,n)flow[i][j]=capacity[i][j]=0;
    REP(u,n)REP(j,G[u].size()){
      edge e = G[u][j];
      capacity[u][e.to] += e.cost;
    }
    ll total = 0;
    while(true){
      REP(i,n)level[i] = -1;
      level[s] = 0;
      queue<int> Q; Q.push(s);
      int d = n;
      while(!Q.empty()){
        int u = Q.front(); Q.pop();
        REP(i,G[u].size()){
          edge e = G[u][i];
          if(RESIDUE(u,e.to) > 0 && level[e.to] == -1){
            Q.push(e.to);
            level[e.to] = level[u] + 1;
          }
        }
      }
      REP(i,n)finished[i]=false;
      bool flag = false;
      while(true){
        ll f = dfs(s,t,INF);
        if(f==0)break;
        total += f;
        flag = true;
      }
      if(!flag)break;
    }
    return total;
  }
};

int main(){
  if(false){
    FOR(a,1,65)FOR(b,1,65){
      ll ccc = calc(a,b);
      ll x = a*b;
      dinic D(2*x+2);
      int s = 2*x;
      int t = 2*x+1;
      REP(i,x)if(i+1!=a)D.add_edge(s,i,1);
      REP(i,x)if(i+1!=b)D.add_edge(x+i,t,1);
      // DEBUG("YO");
      REP(i,x)REP(j,x){
        if((i+1)*(j+1)>=x)break;
        D.add_edge(i,x+j,1);
        // DEBUG(i);
        // DEBUG(j);
      }
      int ans = D.calc(s,t);
      if(ans != ccc){
        DEBUG("NG");
        DEBUG(ccc);
        DEBUG(ans);
        DEBUG(a);
        DEBUG(b);
        return 0;
      }
    }
    return 0;
  }
  int q;
  scanf("%d",&q);
  while(q--){
    ll a,b;
    cin>>a>>b;
    printf("%lld\n",calc(a,b));
  }
  return 0;
}


Measured memory_bytes: 256