{"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\u003eVasya has a string $$$s$$$ of length $$$n$$$. He decides to make the following modification to the string: \u003c/p\u003e\u003col\u003e \u003cli\u003e Pick an integer $$$k$$$, ($$$1 \\leq k \\leq n$$$). \u003c/li\u003e\u003cli\u003e For $$$i$$$ from $$$1$$$ to $$$n-k+1$$$, reverse the substring $$$s[i:i+k-1]$$$ of $$$s$$$. For example, if string $$$s$$$ is \u003cspan class\u003d\"tex-font-style-tt\"\u003eqwer\u003c/span\u003e and $$$k \u003d 2$$$, below is the series of transformations the string goes through: \u003cul\u003e \u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eqwer\u003c/span\u003e (original string) \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003ewqer\u003c/span\u003e (after reversing the first substring of length $$$2$$$) \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003eweqr\u003c/span\u003e (after reversing the second substring of length $$$2$$$) \u003c/li\u003e\u003cli\u003e \u003cspan class\u003d\"tex-font-style-tt\"\u003ewerq\u003c/span\u003e (after reversing the last substring of length $$$2$$$) \u003c/li\u003e\u003c/ul\u003e Hence, the resulting string after modifying $$$s$$$ with $$$k \u003d 2$$$ is \u003cspan class\u003d\"tex-font-style-tt\"\u003ewerq\u003c/span\u003e. \u003c/li\u003e\u003c/ol\u003e\u003cp\u003eVasya wants to choose a $$$k$$$ such that the string obtained after the above-mentioned modification is lexicographically smallest possible among all choices of $$$k$$$. Among all such $$$k$$$, he wants to choose the smallest one. Since he is busy attending Felicity 2020, he asks for your help.\u003c/p\u003e\u003cp\u003eA string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds: \u003c/p\u003e\u003cul\u003e \u003cli\u003e $$$a$$$ is a prefix of $$$b$$$, but $$$a \\ne b$$$; \u003c/li\u003e\u003cli\u003e in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$. \u003c/li\u003e\u003c/ul\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eEach test contains multiple test cases. \u003c/p\u003e\u003cp\u003eThe first line contains the number of test cases $$$t$$$ ($$$1 \\le t \\le 5000$$$). The description of the test cases follows.\u003c/p\u003e\u003cp\u003eThe first line of each test case contains a single integer $$$n$$$ ($$$1 \\le n \\le 5000$$$)\u0026nbsp;— the length of the string $$$s$$$.\u003c/p\u003e\u003cp\u003eThe second line of each test case contains the string $$$s$$$ of $$$n$$$ lowercase latin letters.\u003c/p\u003e\u003cp\u003eIt is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each testcase output two lines:\u003c/p\u003e\u003cp\u003eIn the first line output the lexicographically smallest string $$$s\u0027$$$ achievable after the above-mentioned modification. \u003c/p\u003e\u003cp\u003eIn the second line output the appropriate value of $$$k$$$ ($$$1 \\leq k \\leq n$$$) that you chose for performing the modification. If there are multiple values of $$$k$$$ that give the lexicographically smallest string, output the smallest value of $$$k$$$ among them.\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\u003e6\n4\nabab\n6\nqwerty\n5\naaaaa\n6\nalaska\n9\nlfpbavjsm\n1\np\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eabab\n1\nertyqw\n3\naaaaa\n1\naksala\n6\navjsmbpfl\n5\np\n1\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 testcase of the first sample, the string modification results for the sample \u003cspan class\u003d\"tex-font-style-tt\"\u003eabab\u003c/span\u003e are as follows : \u003c/p\u003e\u003cul\u003e \u003cli\u003e for $$$k \u003d 1$$$ : \u003cspan class\u003d\"tex-font-style-tt\"\u003eabab\u003c/span\u003e \u003c/li\u003e\u003cli\u003e for $$$k \u003d 2$$$ : \u003cspan class\u003d\"tex-font-style-tt\"\u003ebaba\u003c/span\u003e \u003c/li\u003e\u003cli\u003e for $$$k \u003d 3$$$ : \u003cspan class\u003d\"tex-font-style-tt\"\u003eabab\u003c/span\u003e \u003c/li\u003e\u003cli\u003e for $$$k \u003d 4$$$ : \u003cspan class\u003d\"tex-font-style-tt\"\u003ebaba\u003c/span\u003e\u003cp\u003eThe lexicographically smallest string achievable through modification is \u003cspan class\u003d\"tex-font-style-tt\"\u003eabab\u003c/span\u003e for $$$k \u003d 1$$$ and $$$3$$$. Smallest value of $$$k$$$ needed to achieve is hence $$$1$$$. \u003c/p\u003e\u003c/li\u003e\u003c/ul\u003e"}}]}