#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a,b;
signed main(){
	scanf("%lld",&n);
	while(n--){
		scanf("%lld %lld",&a,&b);
		ll ans=sqrt(a*b);
		if(ans*(ans+1)<a*b) ans=ans*2-1;
		else if(ans*ans==a*b&&a!=b) ans=2*(ans-1)-1;
		else ans=2*(ans-1);
		printf("%lld\n",ans);
	}
}