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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Linq;
using System.Text;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int q = sc.NextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++)
        {
            sb.AppendLine(Q(sc.NextLong(), sc.NextLong()).ToString());
        }
        Console.Write(sb);
    }

    long Q(long a, long b)
    {
        if (a == b)
        {
            // どちらかの順位が低い人
            // (x+y)(x-y) = x^2-y^2なので 値が小さくなるようにできる
            return (a - 1) * 2;
        }
        if (a > b) return Q(b, a);
        // a < b
        long ab = a * b;

        // 1回目の順位が低い かつ 2回目が高い人
        long aa = (ab - 1) / (b + 1);
        // 2回目が低い人
        // (a+1)*c <= ab-1
        // (a+c)*1 <= ab-1
        // ((a+1+c)/2)^2 <= ab-1
        long sqrt = 0;
        long ng = 1000000000;
        while (ng - sqrt > 1)
        {
            long mid = (sqrt + ng) / 2;
            if (mid * mid <= (ab - 1)) sqrt = mid;
            else ng = mid;
        }
        // Console.WriteLine($"{sqrt}^2<{ab}");
        long bb;
        if (sqrt * (sqrt + 1) <= ab - 1)
        {
            bb = 2 * sqrt - a;
        }
        else
        {
            bb = 2 * sqrt - a - 1;
        }


        return aa + bb;
    }
    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}