#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long int64;
int64 a,b;
int64 solve()
{
    int64 ret;
    int64 c,d=a*b;
    for(int64 i=sqrt(static_cast<long double>(d-1));i<max({a,b});i++)
    {
        if(d>i*i)c=i;
        else break;
    }
    ret=2*c;
    if(a<=c)ret-=1;
    if(b<=c)ret-=1;
    if(c*(c+1)>=d)ret-=1;
    return ret;
}
int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        cin>>a>>b;
        cout<<solve()<<endl;
    }
    return 0;
}