#include<bits/stdc++.h>
using namespace std;
signed main(){
	int q;
	cin >> q;
	while(q--){
		long long a,b;
		cin >> a >> b;
		long long mult = a*b;
		long long t = sqrt(mult);
		if(t*(t+1)<mult){
			cout << t*2-1 << endl;
		}
		else if(t*t==mult){
			if(a!=b){
				cout << (t-1)*2-1<<endl;
			}
			else{
				cout << (t-1)*2<<endl;
			}
		}
		else{
			cout << (t-1)*2<<endl;
		}
	}
}