Problem:
Score : 700 points

Problem Statement

10^{10^{10}} participants, including Takahashi, competed in two programming contests.
In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.

The score of a participant is the product of his/her ranks in the two contests.

Process the following Q queries:

In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.

Constraints

1 \leq Q \leq 100

1\leq A_i,B_i\leq 10^9(1\leq i\leq Q)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
A_1 B_1
:
A_Q B_Q

Output

For each query, print the maximum possible number of participants whose scores are smaller than Takahashi's.

Sample Input 1

8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Sample Output 1

1
12
4
11
14
57
31
671644785

Let us denote a participant who was ranked x-th in the first contest and y-th in the second contest as (x,y).

In the first query, (2,1) is a possible candidate of a participant whose score is smaller than Takahashi's. There are never two or more participants whose scores are smaller than Takahashi's, so we should print 1.

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn reads<T>() -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    read_line()
        .split_whitespace()
        .map(|w| w.parse().unwrap())
        .collect()
}

fn f(a: i64, b: i64) -> i64 {
    let c = a * b;

    let mut ans = 0;

    let mut ok = 1;
    let mut ng = a;

    while (ok - ng).abs() > 1 {
        let mid = (ok + ng) / 2;

        let t = c / mid;
        let u = c / (mid + 1);

        if t - u > 1 {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    println!("ok = {}", ok);

    ans += ok - 1;
    let mut prev = c + 1;

    for i in ok..a {
        let cur = (c - 1) / i;
        let cur = if cur == b { cur - 1 } else { cur };
        let cur = if cur == prev { cur - 1 } else { cur };
        if cur < 1 {
            continue;
        }

        println!("* ({}, {})", i, cur);

        prev = cur;
        ans += 1;
    }

    ans
}

fn main() {
    /*
1, 49
2, 24
3, 16
4, 12
5, 9
6, 8
7, 7
8, 6
9, 4
11, 3
12, 2
13, 1
12

q*/

    let q: usize = reads()[0];

    for _ in 0..q {
        let (a, b) = {
            let mut t: Vec<i64> = reads();
            // t.sort();
            (t[0], t[1])
        };

        let c = a * b;
        let sqc = (c as f64).sqrt() as i64;

        if c < 10000 {
            let mut ccc = 0;
            let mut used = vec![false; (c + 1) as usize];
            for i in 1..c + 1 {
                for j in (1..c + 1).rev() {
                    if i * j >= c {
                        continue;
                    }
                    if i == a || j == b {
                        continue;
                    }
                    if used[j as usize] {
                        continue;
                    }
                    used[j as usize] = true;
                    ccc += 1;
                    // println!("{}, {}", i, j);
                    break;
                }
            }
            println!("{}", ccc);
        } else {
            // let ans = f(a, b) + f(b, a);

            println!("{}", sqc * 2 - 2 + 1);
        }
    }
}