#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int q; cin >> q;
	while(q--){
		ll a,b; cin >> a >> b;
		if(a>b)swap(a,b);
		if(a==b){
			printf("%lld\n",2*(a-1));
		}else{
			double pp=sqrt(a*b);
			ll p=pp;
			ll ans=0;
			if(p*p==a*b){
				p--;
			}
			else if(p*(p+1)>=a*b){
				ans--;
			}
			ans+=p*2-1;
			printf("%lld\n",ans );
		}
	}
}
