#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

typedef unsigned long long LL;

int main() {
    int Q;
    LL A, B, C;
    double c;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> A >> B;
        if (A == B) {
            cout << 2 * A - 2 << endl;
        }
        else {
            c = sqrt(A * B);
            C = LL(c);
            if (C * (C + 1) < A * B){
                cout << 2 * C - 1 << endl;
            }
            else if (C == c) cout << 2 * C - 3 << endl;
            else cout << 2 * C - 2 << endl;
        }
    }
    return 0;
}