#include <bits/stdc++.h>
using namespace std;
int64_t solution(int64_t a,int64_t b)
{
	int64_t key,target=a*b;
	for (int64_t i=sqrt(static_cast<long double>(target -1));i<std::max({a,b});++i)
	{
		if (target>i*i)
		key=i;
		else
		break;
	}
	int64_t ans=2*key;
	if (a<=key)
		ans-=1;
	if (b<=key)
		ans-=1;
	if (key*(key+1)>=target)
		ans-=1;
	return ans;
}
 
int main()
{
	int q;
	std::cin>>q;
	for (int i=0;i<q;++i)
	{
		int64_t a,b;
		std::cin>>a>>b;
		std::cout<<solution(a,b)<<std::endl;
	}
}