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 ulong[t]; for (var u = 0; u < t; ++u) { var c = NList; var (a, b) = (c[0], c[1]); ans[u] = Problem((ulong)a, (ulong)b); } WriteLine(string.Join("\n", ans)); } static ulong Problem(ulong a, ulong b) { checked { var ok = (ulong)((Math.Sqrt(a) + Math.Sqrt(b)) * 1.1 + 1); var ng = (ulong)0; while (ok - ng > 1) { var mid = (ok + ng) / 2; if (mid * mid < a + b) ng = mid; else if ((mid * mid - a - b) * (mid * mid - a - b) > 4 * a * b) ok = mid; else ng = mid; } return ok; } } }