local mfl, mce = math.floor, math.ceil local mab = math.abs local mmi, mma = math.min, math.max local function llprint(llnumber) local str = tostring(llnumber):gsub("LL", "") print(str) end local q = io.read("*n") for iq = 1, q do local n, i, j = io.read("*n", "*n", "*n") n = n - 1 if n % 2 == 0 then local center = mfl(n / 2) local radius = mma(mab(i - center), mab(j - center)) local tot = (1LL + n) * (1LL + n) if radius == 0 then llprint(tot - 1LL) else local v = (radius * 2LL - 1LL) * (radius * 2LL - 1LL) local line = radius * 2LL if center - radius == i and center + radius ~= j then -- top left local diff_from_topleft = j - (center - radius) local z = v + line * 4LL - diff_from_topleft llprint(tot - z) elseif center + radius == j and center + radius ~= i then -- right top local diff_from_righttop = i - (center - radius) local z = v + line * 3LL - diff_from_righttop llprint(tot - z) elseif center + radius == i and center - radius ~= j then -- bottom right local diff_from_bottomright = center + radius - j local z = v + line * 2LL - diff_from_bottomright llprint(tot - z) else -- left bottom local diff_from_leftbottom = center + radius - i local z = v + line - diff_from_leftbottom llprint(tot - z) end end else -- n % 2 == 1 local hn = mfl((n + 1) / 2) local radius = i < hn and hn - i or i - (hn - 1) do local tmp = j < hn and hn - j or j - (hn - 1) radius = mma(radius, tmp) end local rl, rr = hn - radius, hn - 1 + radius local tot = (1LL + n) * (1LL + n) local v = (radius * 2LL - 2LL) * (radius * 2LL - 2LL) local line = radius * 2LL - 1LL if rl == i and rr ~= j then -- top left local diff_from_topleft = j - rl local z = v + line * 4LL - diff_from_topleft llprint(tot - z) elseif rr == j and rr ~= i then -- right top local diff_from_righttop = i - rl local z = v + line * 3LL - diff_from_righttop llprint(tot - z) elseif rr == i and rl ~= j then -- bottom right local diff_from_bottomright = rr - j local z = v + line * 2LL - diff_from_bottomright llprint(tot - z) else -- left bottom local diff_from_leftbottom = rr - i local z = v + line - diff_from_leftbottom llprint(tot - z) end end end