using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var t = NN; var ans = new long[t]; for (var u = 0; u < t; ++u) { var c = NList; var (a, b) = (c[0], c[1]); var m2 = 4 * a * b; var m = (long)Math.Sqrt(m2); while (m * m < m2) ++m; while ((m - 1) * (m - 1) >= m2) --m; var ng = 0L; var ok = 3_000_000_000L; while (ok - ng > 1) { var mid = (ok + ng) / 2; if (m < mid * mid - a - b) ok = mid; else ng = mid; } ans[u] = ok; } WriteLine(string.Join("\n", ans)); } }