{"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\u003eSome programming website is establishing a secure communication protocol. For security reasons, they want to choose several more or less random strings.\u003c/p\u003e\u003cp\u003eInitially, they have a string $$$s$$$ consisting of lowercase English letters. Now they want to choose $$$q$$$ strings using the following steps, and you are to help them.\u003c/p\u003e\u003col\u003e \u003cli\u003e A string $$$x$$$ consisting of lowercase English letters and integers $$$l$$$ and $$$r$$$ ($$$1 \\leq l \\leq r \\leq |s|$$$) are chosen. \u003c/li\u003e\u003cli\u003e Consider all non-empty distinct substrings of the $$$s_l s_{l + 1} \\ldots s_r$$$, that is all distinct strings $$$s_i s_{i+1} \\ldots s_{j}$$$ where $$$l \\le i \\le j \\le r$$$. Among all of them choose all strings that are lexicographically greater than $$$x$$$. \u003c/li\u003e\u003cli\u003e If there are no such strings, you should print $$$-1$$$. Otherwise print the lexicographically smallest among them. \u003c/li\u003e\u003c/ol\u003e\u003cp\u003eString $$$a$$$ is lexicographically less than string $$$b$$$, if either $$$a$$$ is a prefix of $$$b$$$ and $$$a \\ne b$$$, or there exists such a position $$$i$$$ ($$$1 \\le i \\le min(|a|, |b|)$$$), such that $$$a_i \u0026lt; b_i$$$ and for all $$$j$$$ ($$$1 \\le j \u0026lt; i$$$) $$$a_j \u003d b_j$$$. Here $$$|a|$$$ denotes the length of the string $$$a$$$.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe first line of input contains a non-empty string $$$s$$$ ($$$1 \\leq |s| \\leq 10^{5}$$$) consisting of lowercase English letters.\u003c/p\u003e\u003cp\u003eThe second line contains an integer $$$q$$$ ($$$1 \\le q \\le 2 \\cdot 10^5$$$)\u0026nbsp;— the number of strings to select.\u003c/p\u003e\u003cp\u003eEach of the next $$$q$$$ lines contains two integers $$$l$$$, $$$r$$$ ($$$1 \\leq l \\leq r \\leq |s|$$$) and a non-empty string $$$x$$$ consisting of lowercase English letters. The total length of strings $$$x$$$ for all queries does not exceed $$$2 \\cdot 10^{5}$$$.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eOutput $$$q$$$ lines, each of them should contain the desired string or $$$-1$$$, if there is no such string.\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\u003ebaa\n5\n1 2 ba\n2 3 a\n1 2 b\n2 3 aa\n1 3 b\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e-1\naa\nba\n-1\nba\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","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\u003ebacb\n4\n1 2 ba\n2 3 ac\n1 3 ac\n3 4 c\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e-1\nc\nb\ncb\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","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\u003ebba\n1\n1 1 b\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e-1\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\u003eConsider the first example.\u003c/p\u003e\u003cp\u003eThe string $$$s$$$ is \"\u003cspan class\u003d\"tex-font-style-tt\"\u003ebaa\u003c/span\u003e\". The queries are as follows.\u003c/p\u003e\u003col\u003e \u003cli\u003e We consider the substring $$$s_1 s_2$$$ that is \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eba\u003c/span\u003e\". It has substrings \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eb\u003c/span\u003e\", \"\u003cspan class\u003d\"tex-font-style-tt\"\u003ea\u003c/span\u003e\" and \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eba\u003c/span\u003e\", since none of them is greater than the query string \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eba\u003c/span\u003e\", the answer is $$$-1$$$.\u003c/li\u003e\u003cli\u003e We consider substring \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eaa\u003c/span\u003e\". Among its substrings only \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eaa\u003c/span\u003e\" is greater than the query string \"\u003cspan class\u003d\"tex-font-style-tt\"\u003ea\u003c/span\u003e\". So the answer is \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eaa\u003c/span\u003e\".\u003c/li\u003e\u003cli\u003e We consider substring \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eba\u003c/span\u003e\". Out of \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eb\u003c/span\u003e\", \"\u003cspan class\u003d\"tex-font-style-tt\"\u003ea\u003c/span\u003e\" and \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eba\u003c/span\u003e\" only \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eba\u003c/span\u003e\" is greater than the query string \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eb\u003c/span\u003e\", so the answer is \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eba\u003c/span\u003e\".\u003c/li\u003e\u003cli\u003e We consider substring \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eaa\u003c/span\u003e\". No substring of \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eaa\u003c/span\u003e\" is greater than the query string \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eaa\u003c/span\u003e\" so the answer is $$$-1$$$.\u003c/li\u003e\u003cli\u003e We consider substring \"\u003cspan class\u003d\"tex-font-style-tt\"\u003ebaa\u003c/span\u003e\" and it has (among others) substrings \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eba\u003c/span\u003e\", \"\u003cspan class\u003d\"tex-font-style-tt\"\u003ebaa\u003c/span\u003e\" which are greater than the query string \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eb\u003c/span\u003e\". Since \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eba\u003c/span\u003e\" is lexicographically smaller than \"\u003cspan class\u003d\"tex-font-style-tt\"\u003ebaa\u003c/span\u003e\", the answer is \"\u003cspan class\u003d\"tex-font-style-tt\"\u003eba\u003c/span\u003e\". \u003c/li\u003e\u003c/ol\u003e"}}]}