#include <iostream>
#include <complex>
using namespace std;

int main() {
	long Q, A, B, C, ans;
	cin >> Q;
	for(int i = 0; i < Q; i++){
		cin >> A >> B;
		if(A > B) swap(A, B);
		C = floor(sqrt(A * B));
		if(C == sqrt(A * B)) C--;
		if(A == B) ans = 2 * A - 2;
		else if((A + 1) == B) ans = 2 * A -2;
		else if((C * (C + 1)) >= (A * B)) ans = 2 * C - 2;
		else if((C * C) < (A * B)) ans = 2 * C - 1;
		cout << ans << endl;
	}
	return 0;
}