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(); // Test(); } static void Test() { var r = new Random(); var count = 0; var now = DateTime.Now; while (true) { var a = r.Next(1_000_000_000) + 1; var b = r.Next(1_000_000_000) + 1; var s = Problem(a, b); ++count; if (count == 200000) break; } WriteLine((DateTime.Now - now).TotalSeconds); } 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]); ans[u] = (long)Problem(a, b); } WriteLine(string.Join("\n", ans)); } static decimal Problem(long a, long b) { // checked { var ok = ((decimal)Math.Sqrt(a) + (decimal)Math.Sqrt(b)) * 2; var ng = decimal.Zero; while (ok - ng > 1) { var mid = decimal.Floor((ok + ng) / 2); if ((mid * mid - a - b) * (mid * mid - a - b) > 4 * a * b) ok = mid; else ng = mid; } return ok; // } } }