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

void main() {
    auto Q = readln.chomp.to!int;
    long[] ans;
    foreach (i; 0..Q) {
        auto tmp = readln.split.to!(real[]);
        auto A = tmp[0], B = tmp[1];
        auto score = A * B;


        auto frontMax = cast(long)sqrt(score);
        if (frontMax * (cast(long)score/frontMax) == cast(long)score && (cast(long)score/frontMax) - frontMax <= 1) frontMax--;
        auto result = frontMax * 2;
        if (frontMax == cast(long)score / frontMax) result--;

        if (A <= frontMax) result--;
        if (B <= frontMax) result--;

        ans ~= result;

        // 8 36

        // 8 9

        // 1 71
        // 2 35
        // 3 23
        // 4 17
        // 5 14
        // 6 11
        // 7 10
        // 8 9

        // 1 4
        
        // 1 3
        // 2 2
        // 3 1

        // 10 5

        // 1 49
        // 2 24
        // 3 16
        // 4 12
        // 5 9
        // 6 8
        // 7 7
    }
    foreach (a; ans) writeln(a);
}
