import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto Q = readln.chomp.to!int;
    foreach (_; 0..Q) {
        auto ab = readln.split.to!(long[]);
        auto A = ab[0];
        auto B = ab[1];
        if (A > B) swap(A, B);

        if (A == B || A+1 == B) {
            writeln(2*(A-1));
            continue;
        }

        auto c = sqrt((A*B).to!double).to!long;
        if (c^^2 == A*B) --c;
        if (c * (c+1) >= A*B) {
            writeln(2*(c-1));
        } else {
            writeln(2*c-1);
        }
    }
}