#include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll sqrtll(ll x){
  assert(x >= 0);
  ll n = sqrt(x);
  while(n * n > x) --n;
  while((n+1)*(n+1) <= x) ++n;
  return n;
}


int main(){
	// input
	int N; cin >> N;
	while(N--){
		ll A,B; cin >> A >> B;
		// solve: meguru binary search
		ll lo = max(sqrtll(A),sqrtll(B)), hi = 1e6;
		while(hi - lo > 1){
			ll mid = (lo + hi) / 2;
			ll lhs = mid * mid - (A + B);
			ll rhs = 4 * A * B;
			
			bool greater = (lhs > 3e9);
			if(!greater){
				if(lhs * lhs > rhs)
				greater = 1;
			}
			
			// judge
			if(greater) hi = mid;
			else lo = mid;
		}
		// output
		cout << hi << endl;
	}
}