{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n div.illustration {\n float: right;\n padding-left: 20px;\n }\n div.illustration .illustration {\n width: 100%;\n border-radius: 4px;\n }\n pre {\n display: block;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n color: #333;\n word-break: break-all;\n word-wrap: break-word;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\n \u003cp\u003eA student wants to send to his friend a message, which is a\n text string \u003cspan class\u003d\"tex2jax_process\"\u003e$p$\u003c/span\u003e consisting\n of only lowercase latin alphabet letters. To encrypt his\n message, he creates a lowercase alphabet string \u003cspan class\u003d\"tex2jax_process\"\u003e$h$\u003c/span\u003e of size \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e that contains \u003cspan class\u003d\"tex2jax_process\"\u003e$p$\u003c/span\u003e as a substring. The student is\n curious to find out how many different ways there are to create\n such a string \u003cspan class\u003d\"tex2jax_process\"\u003e$h$\u003c/span\u003e.\u003c/p\u003e\n \u003cp\u003eGiven two positive integers \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$M$\u003c/span\u003e and a string \u003cspan class\u003d\"tex2jax_process\"\u003e$p$\u003c/span\u003e consisting of only lowercase latin\n alphabet letters, let’s denote \u003cspan class\u003d\"tex2jax_process\"\u003e$K$\u003c/span\u003e to be the total number of\n different ways to create a lowercase alphabet string\n \u003cspan class\u003d\"tex2jax_process\"\u003e$h$\u003c/span\u003e of size \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e such that \u003cspan class\u003d\"tex2jax_process\"\u003e$p$\u003c/span\u003e is a substring of \u003cspan class\u003d\"tex2jax_process\"\u003e$h$\u003c/span\u003e. Your task is to find the\n remainder of \u003cspan class\u003d\"tex2jax_process\"\u003e$K$\u003c/span\u003e divided\n by \u003cspan class\u003d\"tex2jax_process\"\u003e$M$\u003c/span\u003e.\u003c/p\u003e\n \u003ch2\u003eInput\u003c/h2\u003e\n \u003cp\u003eThe input consists of several datasets. The first line of\n the input contains the number of datasets which is a positive\n integer and is not greater than \u003cspan class\u003d\"tex2jax_process\"\u003e$20$\u003c/span\u003e. The following lines describe the\n datasets.\u003c/p\u003e\n \u003cp\u003eEach dataset is described by the following lines:\u003c/p\u003e\n \u003cul class\u003d\"itemize\"\u003e\n \u003cli\u003e\n \u003cp\u003eThe first line contains two positive integers\n \u003cspan class\u003d\"tex2jax_process\"\u003e$n$\u003c/span\u003e and \u003cspan class\u003d\"tex2jax_process\"\u003e$M$\u003c/span\u003e, where \u003cspan class\u003d\"tex2jax_process\"\u003e$n \\leq {10}^{12}$\u003c/span\u003e and\n \u003cspan class\u003d\"tex2jax_process\"\u003e$M \\leq\n {10}^{12})$\u003c/span\u003e;\u003c/p\u003e\n \u003c/li\u003e\n \u003cli\u003e\n \u003cp\u003eThe next line contains the text string \u003cspan class\u003d\"tex2jax_process\"\u003e$p$\u003c/span\u003e consisting of at most\n \u003cspan class\u003d\"tex2jax_process\"\u003e$50$\u003c/span\u003e lowercase latin\n alphabet letters.\u003c/p\u003e\n \u003c/li\u003e\n \u003c/ul\u003e\n \u003ch2\u003eOutput\u003c/h2\u003e\n \u003cp\u003eFor each dataset, output the remainder of \u003cspan class\u003d\"tex2jax_process\"\u003e$K$\u003c/span\u003e divided by \u003cspan class\u003d\"tex2jax_process\"\u003e$M$\u003c/span\u003e.\u003c/p\u003e\n \u003ch2\u003eSample 1\u003c/h2\u003e\u003cbody\u003e\u003ctable class\u003d\"vjudge_sample\"\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\u003e2\n2 100\nab\n3 100\nab\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\n52\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\u003c/body\u003e\n "}}]}