{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027$$$$$$\u0027, right: \u0027$$$$$$\u0027, display: true},\n {left: \u0027$$$\u0027, right: \u0027$$$\u0027, display: false},\n {left: \u0027$$\u0027, right: \u0027$$\u0027, display: true},\n {left: \u0027$\u0027, right: \u0027$\u0027, display: false}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eGame studio \"DbZ Games\" wants to introduce another map in their popular game \"Valiant\". This time, the map named \"Panvel\" will be based on the city of Mumbai.\u003c/p\u003e\u003cp\u003eMumbai can be represented as $$$n \\times m$$$ cellular grid. Each cell $$$(i, j)$$$ ($$$1 \\le i \\le n$$$; $$$1 \\le j \\le m$$$) of the grid is occupied by a cuboid building of height $$$a_{i,j}$$$.\u003c/p\u003e\u003cp\u003eThis time, DbZ Games want to make a map that has perfect vertical gameplay. That\u0027s why they want to choose an $$$l \\times l$$$ square inside Mumbai, such that each building inside the square has a height of at least $$$l$$$.\u003c/p\u003e\u003cp\u003eCan you help DbZ Games find such a square of the maximum possible size $$$l$$$?\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\leq t \\leq 1000$$$). Description of the test cases follows.\u003c/p\u003e\u003cp\u003eThe first line of each test case contains two positive integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le m$$$; $$$1 \\leq n \\cdot m \\leq 10^6$$$).\u003c/p\u003e\u003cp\u003eThe $$$i$$$-th of next $$$n$$$ lines contains $$$m$$$ integers $$$a_{i,1}, a_{i,2}, \\dots, a_{i,m}$$$ ($$$1 \\leq a_{i,j} \\leq 10^6$$$)\u0026nbsp;— heights of buildings on the $$$i$$$-th row.\u003c/p\u003e\u003cp\u003eIt\u0027s guaranteed that the sum of $$$n \\cdot m$$$ over all test cases doesn\u0027t exceed $$$10^6$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each test case, print the maximum side length $$$l$$$ of the square DbZ Games can choose.\u003c/p\u003e"}},{"title":"Examples","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4\n2 2\n2 3\n4 5\n1 3\n1 2 3\n2 3\n4 4 3\n2 1 4\n5 6\n1 9 4 6 5 8\n10 9 5 8 11 6\n24 42 32 8 11 1\n23 1 9 69 13 3\n13 22 60 12 14 17\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\n1\n1\n3\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"HTML","content":"\u003cp\u003eIn the first test case, we can choose the square of side $$$l \u003d 2$$$ (i.\u0026nbsp;e. the whole grid) since the heights of all buildings are greater than or equal to $$$2$$$.\u003c/p\u003e\u003cp\u003eIn the second test case, we can only choose the side as $$$1$$$, so the answer is $$$1$$$.\u003c/p\u003e\u003cp\u003eIn the third test case, there are no squares of size $$$2$$$ that have all buildings of height at least $$$2$$$, so the answer is $$$1$$$. \u003c/p\u003e"}}]}