import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int q;
    scan(q);

    while (q--) {
        long ai, bi;
        scan(ai, bi);
        solve(ai, bi);
    }
}

void solve(long ai, long bi) {
    long l = sqrt(ai*bi);
    debug {
        writefln("l:%s", l);
    }
    long ans;

    if (l*(l+1) < ai*bi) {
        ans = 2*l - 1;
    }
    else {
        ans = 2*l - 2;
    }

    if (ai == bi) ans++;

    writeln(ans);
}

long sqrt(long x) {
    long btm = 0, top = x;

    while (top - btm > 1) {
        long mid = (top + btm) / 2;

        if (mid < (x+mid-1)/mid) {
            btm = mid;
        }
        else {
            top = mid;
        }
    }

    return btm;
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
