{"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\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eYou are given an array $$$a$$$ consisting of $$$n$$$ integers. You have to find the length of the smallest (shortest) \u003cspan class\u003d\"tex-font-style-it\"\u003eprefix\u003c/span\u003e of elements you need to erase from $$$a$$$ to make it a \u003cspan class\u003d\"tex-font-style-it\"\u003egood\u003c/span\u003e array. Recall that the prefix of the array $$$a\u003d[a_1, a_2, \\dots, a_n]$$$ is a subarray consisting several first elements: the prefix of the array $$$a$$$ of length $$$k$$$ is the array $$$[a_1, a_2, \\dots, a_k]$$$ ($$$0 \\le k \\le n$$$).\u003c/p\u003e\u003cp\u003eThe array $$$b$$$ of length $$$m$$$ is called \u003cspan class\u003d\"tex-font-style-it\"\u003egood\u003c/span\u003e, if you can obtain a \u003cspan class\u003d\"tex-font-style-bf\"\u003enon-decreasing\u003c/span\u003e array $$$c$$$ ($$$c_1 \\le c_2 \\le \\dots \\le c_{m}$$$) from it, repeating the following operation $$$m$$$ times (initially, $$$c$$$ is empty):\u003c/p\u003e\u003cul\u003e \u003cli\u003e select either the first or the last element of $$$b$$$, remove it from $$$b$$$, and append it to the end of the array $$$c$$$. \u003c/li\u003e\u003c/ul\u003e\u003cp\u003eFor example, if we do $$$4$$$ operations: take $$$b_1$$$, then $$$b_{m}$$$, then $$$b_{m-1}$$$ and at last $$$b_2$$$, then $$$b$$$ becomes $$$[b_3, b_4, \\dots, b_{m-3}]$$$ and $$$c \u003d[b_1, b_{m}, b_{m-1}, b_2]$$$.\u003c/p\u003e\u003cp\u003eConsider the following example: $$$b \u003d [1, 2, 3, 4, 4, 2, 1]$$$. This array is \u003cspan class\u003d\"tex-font-style-bf\"\u003egood\u003c/span\u003e because we can obtain \u003cspan class\u003d\"tex-font-style-bf\"\u003enon-decreasing\u003c/span\u003e array $$$c$$$ from it by the following sequence of operations:\u003c/p\u003e\u003col\u003e \u003cli\u003e take the first element of $$$b$$$, so $$$b \u003d [2, 3, 4, 4, 2, 1]$$$, $$$c \u003d [1]$$$; \u003c/li\u003e\u003cli\u003e take the last element of $$$b$$$, so $$$b \u003d [2, 3, 4, 4, 2]$$$, $$$c \u003d [1, 1]$$$; \u003c/li\u003e\u003cli\u003e take the last element of $$$b$$$, so $$$b \u003d [2, 3, 4, 4]$$$, $$$c \u003d [1, 1, 2]$$$; \u003c/li\u003e\u003cli\u003e take the first element of $$$b$$$, so $$$b \u003d [3, 4, 4]$$$, $$$c \u003d [1, 1, 2, 2]$$$; \u003c/li\u003e\u003cli\u003e take the first element of $$$b$$$, so $$$b \u003d [4, 4]$$$, $$$c \u003d [1, 1, 2, 2, 3]$$$; \u003c/li\u003e\u003cli\u003e take the last element of $$$b$$$, so $$$b \u003d [4]$$$, $$$c \u003d [1, 1, 2, 2, 3, 4]$$$; \u003c/li\u003e\u003cli\u003e take the only element of $$$b$$$, so $$$b \u003d []$$$, $$$c \u003d [1, 1, 2, 2, 3, 4, 4]$$$\u0026nbsp;— $$$c$$$ is non-decreasing. \u003c/li\u003e\u003c/ol\u003e\u003cp\u003eNote that the array consisting of one element is \u003cspan class\u003d\"tex-font-style-it\"\u003egood\u003c/span\u003e.\u003c/p\u003e\u003cp\u003ePrint the length of the shortest prefix of $$$a$$$ to delete (erase), to make $$$a$$$ to be a \u003cspan class\u003d\"tex-font-style-it\"\u003egood\u003c/span\u003e array. Note that the required length can be $$$0$$$.\u003c/p\u003e\u003cp\u003eYou have to answer $$$t$$$ independent test cases.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 2 \\cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow.\u003c/p\u003e\u003cp\u003eThe first line of the test case contains one integer $$$n$$$ ($$$1 \\le n \\le 2 \\cdot 10^5$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 2 \\cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.\u003c/p\u003e\u003cp\u003eIt is guaranteed that the sum of $$$n$$$ does not exceed $$$2 \\cdot 10^5$$$ ($$$\\sum n \\le 2 \\cdot 10^5$$$).\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each test case, print the answer: the length of the shortest \u003cspan class\u003d\"tex-font-style-it\"\u003eprefix\u003c/span\u003e of elements you need to erase from $$$a$$$ to make it a \u003cspan class\u003d\"tex-font-style-it\"\u003egood\u003c/span\u003e array.\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\u003e5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 4 5 3 2\n5\n5 4 3 2 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e0\n4\n0\n2\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 of the example, the array $$$a$$$ is already good, so we don\u0027t need to erase any prefix.\u003c/p\u003e\u003cp\u003eIn the second test case of the example, the initial array $$$a$$$ is not good. Let\u0027s erase first $$$4$$$ elements of $$$a$$$, the result is $$$[4, 5, 2]$$$. The resulting array is good. You can prove that if you erase fewer number of first elements, the result will not be good.\u003c/p\u003e"}}]}