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

int main() 
{
    int q; cin >> q;
    while (q--) {
        ll a, b; cin >> a >> b;
        if (a > b) swap(a,b);
        if (a == b || a == b-1) {
            cout << (2*a-2) << "\n";
        }
        else {
            ll c = (ll)sqrt(a*b)-3;
            while ((c+1)*(c+1) < a*b)
              c++;
            if (c*(c+1) >= a*b) {
                cout << 2*c-2 << '\n';
            }
            else {
                cout << 2*c-1 << '\n';
            }
        }
    }
}


