{"trustable":true,"prependHtml":"\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 async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eLet s\u003d$s_1$ $s_2$$ \\cdots $$s_n$ be a string of length n. For any integer k between 1 to n, the $k^{th}$ suffix of s is defined as $s_k$ $s_{k+1}$$ \\cdots $$s_n$. For example, the $4^{th}$ suffix of “contest” is “test” and the $1^{st}$ suffix of “suffix” is “suffix” itself.\u003cbr\u003e\u003cbr\u003eOne can consider lexicographically smallest suffix of s. Let the $k^{th}$ suffix is lexicographically minimum among all suffixes of s. Conveniently, let’s call such k minimum index of s. Given a string t\u003d$t_1$ $t_2 \\cdots t_n$, your task is to calculate the sum of (minimum index of $t_1$ $t_2 \\cdots t_i$)$ \\cdot 1112^{i-1}$ over all i\u003d1,2,3,$ \\cdots $,n. This value may be too large, you are only required to print it modulo $10^9$+7.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains a single integer T (1≤T≤10 000), the number of test cases. Each of the next T lines contains a non-empty string with at most $10^6$ lowercase English letters. The total length of the input string over all test cases doesn’t exceed $2 \\cdot 10^7$."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, you should print the answer in a single line."}},{"title":"Sample","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\u003e1\r\naab\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1238769\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Hint","value":{"format":"HTML","content":"\u003cbr\u003eThe minimum index of “a”, “aa”, “aab” is 1, 2, 1 respectively. So the answer is (1+2\u0026amp;#8729;1112+1112^2) mod (10^9+7)\u003d1238769.\u003cbr\u003e"}}]}