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];

        auto m = sqrt((A*B-1).to!double).to!long;
        auto c = m*2 - (m*(m+1) < A*B ? 0 : 1);
        if (A <= m) c -= 1;
        if (B <= m) c -= 1;
        writeln(c);
    }
}