#include<cmath>
#include<cstdio>
using namespace std;
int main() {
	int Q;
	scanf("%d",&Q);
	while(Q--){
		long long a,b,pr,t,ans;
		scanf("%lld %lld",&a,&b);
		pr=a*b;
		t=sqrt(pr);
		if(t*t+t<pr)
			ans=t*2-1;
		else if(t*t==pr) {
			ans=(t-1)*2;
			if(a!=b) ans--;
		} else
			ans=(t-1)*2;
		printf("%lld\n",ans);
	}
}