#include <bits/stdc++.h>

using namespace std;

using ll = long long;

ll Solve(ll a, ll b) {
    if (a == b) return 2 * a - 2;

    if (b < a) swap(a, b);

    ll lb = a, ub = 2 * b, ab = a * b;
    while (1 < ub - lb) {
        ll mid = 0.5 * (lb + ub);
        ll max_p = (mid + 1) / 2 * (mid / 2 + 1);
        if (max_p < ab) lb = mid;
        else ub = mid;
    }

    return lb - 1;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);

    int q;
    cin >> q;
    while (q--) {
        ll a, b;
        cin >> a >> b;
        cout << Solve(a, b) << '\n';
    }

    return 0;
}
