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

void solve(ll A, ll B){
    if(A > B) swap(A, B);

    if(B==A || B==A+1) cout << 2*A-2 << endl;
    else{
        ll C = floor(sqrt(A*B)) - 1;
        while(true){
            if((C+1)*(C+1)>=A*B) break;
            C++;
        }
        if(C*(C+1) >= A*B) cout << 2*C-2 << endl;
        else cout << 2*C-1 << endl;
    }
}

int main(){
    int Q;  cin >> Q;
    for(int i=0; i<Q; i++){
        ll A,B;  cin >> A >> B;
        solve(A,B);
    }
}
	