{"trustable":false,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cstyle\u003e\n\u003c!--\n /* Font Definitions */\n @font-face\n\t{font-family:Mangal;\n\tpanose-1:2 4 5 3 5 2 3 3 2 2;}\n@font-face\n\t{font-family:\"Cambria Math\";\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\n@font-face\n\t{font-family:Cambria;\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\n@font-face\n\t{font-family:Calibri;\n\tpanose-1:2 15 5 2 2 2 4 3 2 4;}\n@font-face\n\t{font-family:Tahoma;\n\tpanose-1:2 11 6 4 3 5 4 4 2 4;}\n@font-face\n\t{font-family:Garamond;\n\tpanose-1:2 2 4 4 3 3 1 1 8 3;}\n@font-face\n\t{font-family:Verdana;\n\tpanose-1:2 11 6 4 3 5 4 4 2 4;}\n@font-face\n\t{font-family:\"Bernard MT Condensed\";\n\tpanose-1:2 5 8 6 6 9 5 2 4 4;}\n@font-face\n\t{font-family:\"Bookman Old Style\";\n\tpanose-1:2 5 6 4 5 5 5 2 2 4;}\n@font-face\n\t{font-family:\"Courier 10 Pitch\";}\n@font-face\n\t{font-family:\"DejaVu Sans\";}\n@font-face\n\t{font-family:\"\\@Courier 10 Pitch\";}\n@font-face\n\t{font-family:\"\\@DejaVu Sans\";}\n /* Style Definitions */\n p.MsoNormal, li.MsoNormal, div.MsoNormal\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:0in;\n\ttext-align:justify;\n\tline-height:115%;\n\tfont-size:12.0pt;\n\tfont-family:\"Garamond\",\"serif\";}\nh1\n\t{mso-style-link:\"Heading 1 Char\";\n\tmargin:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:justify;\n\tline-height:115%;\n\tpage-break-after:avoid;\n\tfont-size:14.0pt;\n\tfont-family:\"Cambria\",\"serif\";\n\tcolor:green;}\nh2\n\t{mso-style-link:\"Heading 2 Char\";\n\tmargin:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:justify;\n\tpage-break-after:avoid;\n\tfont-size:16.0pt;\n\tfont-family:\"Arial\",\"sans-serif\";\n\tcolor:black;}\nh3\n\t{mso-style-link:\"Heading 3 Char\";\n\tmargin-top:10.0pt;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:justify;\n\tline-height:115%;\n\tpage-break-after:avoid;\n\tfont-size:12.0pt;\n\tfont-family:\"Garamond\",\"serif\";\n\tcolor:#4F81BD;}\np.MsoHeader, li.MsoHeader, div.MsoHeader\n\t{mso-style-link:\"Header Char\";\n\tmargin:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:justify;\n\tfont-size:12.0pt;\n\tfont-family:\"Garamond\",\"serif\";}\np.MsoFooter, li.MsoFooter, div.MsoFooter\n\t{mso-style-link:\"Footer Char\";\n\tmargin:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:justify;\n\tfont-size:12.0pt;\n\tfont-family:\"Garamond\",\"serif\";}\np.MsoTitle, li.MsoTitle, div.MsoTitle\n\t{mso-style-link:\"Title Char\";\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:12.0pt;\n\tmargin-left:0in;\n\ttext-align:center;\n\tfont-size:36.0pt;\n\tfont-family:\"Bernard MT Condensed\",\"serif\";\n\tcolor:green;\n\tletter-spacing:.25pt;}\np.MsoTitleCxSpFirst, li.MsoTitleCxSpFirst, div.MsoTitleCxSpFirst\n\t{mso-style-link:\"Title Char\";\n\tmargin:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:center;\n\tfont-size:36.0pt;\n\tfont-family:\"Bernard MT Condensed\",\"serif\";\n\tcolor:green;\n\tletter-spacing:.25pt;}\np.MsoTitleCxSpMiddle, li.MsoTitleCxSpMiddle, div.MsoTitleCxSpMiddle\n\t{mso-style-link:\"Title Char\";\n\tmargin:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:center;\n\tfont-size:36.0pt;\n\tfont-family:\"Bernard MT Condensed\",\"serif\";\n\tcolor:green;\n\tletter-spacing:.25pt;}\np.MsoTitleCxSpLast, li.MsoTitleCxSpLast, div.MsoTitleCxSpLast\n\t{mso-style-link:\"Title Char\";\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:12.0pt;\n\tmargin-left:0in;\n\ttext-align:center;\n\tfont-size:36.0pt;\n\tfont-family:\"Bernard MT Condensed\",\"serif\";\n\tcolor:green;\n\tletter-spacing:.25pt;}\np.MsoSubtitle, li.MsoSubtitle, div.MsoSubtitle\n\t{mso-style-link:\"Subtitle Char\";\n\tmargin-top:6.0pt;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:center;\n\tline-height:115%;\n\tfont-size:24.0pt;\n\tfont-family:\"Bookman Old Style\",\"serif\";\n\tletter-spacing:.75pt;\n\tfont-weight:bold;}\np.MsoBodyText3, li.MsoBodyText3, div.MsoBodyText3\n\t{mso-style-link:\"Body Text 3 Char\";\n\tmargin:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:justify;\n\tfont-size:12.0pt;\n\tfont-family:\"Verdana\",\"sans-serif\";\n\tcolor:black;}\na:link, span.MsoHyperlink\n\t{color:blue;\n\ttext-decoration:underline;}\na:visited, span.MsoHyperlinkFollowed\n\t{color:purple;\n\ttext-decoration:underline;}\npre\n\t{mso-style-link:\"HTML Preformatted Char\";\n\tmargin:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:justify;\n\tfont-size:10.0pt;\n\tfont-family:\"Courier New\";}\np.MsoAcetate, li.MsoAcetate, div.MsoAcetate\n\t{mso-style-link:\"Balloon Text Char\";\n\tmargin:0in;\n\tmargin-bottom:.0001pt;\n\ttext-align:justify;\n\tfont-size:8.0pt;\n\tfont-family:\"Tahoma\",\"sans-serif\";}\np.MsoNoSpacing, li.MsoNoSpacing, div.MsoNoSpacing\n\t{margin:0in;\n\tmargin-bottom:.0001pt;\n\tfont-size:12.0pt;\n\tfont-family:\"Garamond\",\"serif\";}\np.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.5in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\np.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:.5in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\np.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:.5in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\np.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.5in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\nspan.MsoSubtleEmphasis\n\t{color:gray;\n\tfont-style:italic;}\nspan.HeaderChar\n\t{mso-style-name:\"Header Char\";\n\tmso-style-link:Header;}\nspan.FooterChar\n\t{mso-style-name:\"Footer Char\";\n\tmso-style-link:Footer;}\nspan.Heading2Char\n\t{mso-style-name:\"Heading 2 Char\";\n\tmso-style-link:\"Heading 2\";\n\tfont-family:\"Arial\",\"sans-serif\";\n\tcolor:black;\n\tfont-weight:bold;}\nspan.BodyText3Char\n\t{mso-style-name:\"Body Text 3 Char\";\n\tmso-style-link:\"Body Text 3\";\n\tfont-family:\"Verdana\",\"sans-serif\";\n\tcolor:black;}\nspan.BalloonTextChar\n\t{mso-style-name:\"Balloon Text Char\";\n\tmso-style-link:\"Balloon Text\";\n\tfont-family:\"Tahoma\",\"sans-serif\";}\nspan.HTMLPreformattedChar\n\t{mso-style-name:\"HTML Preformatted Char\";\n\tmso-style-link:\"HTML Preformatted\";\n\tfont-family:\"Courier New\";}\nspan.TitleChar\n\t{mso-style-name:\"Title Char\";\n\tmso-style-link:Title;\n\tfont-family:\"Bernard MT Condensed\",\"serif\";\n\tcolor:green;\n\tletter-spacing:.25pt;}\nspan.Heading3Char\n\t{mso-style-name:\"Heading 3 Char\";\n\tmso-style-link:\"Heading 3\";\n\tfont-family:\"Cambria\",\"serif\";\n\tcolor:#4F81BD;\n\tfont-weight:bold;}\nspan.Heading1Char\n\t{mso-style-name:\"Heading 1 Char\";\n\tmso-style-link:\"Heading 1\";\n\tfont-family:\"Cambria\",\"serif\";\n\tcolor:green;\n\tfont-weight:bold;}\nspan.SubtitleChar\n\t{mso-style-name:\"Subtitle Char\";\n\tmso-style-link:Subtitle;\n\tfont-family:\"Bookman Old Style\",\"serif\";\n\tletter-spacing:.75pt;\n\tfont-weight:bold;}\np.SampleIO, li.SampleIO, div.SampleIO\n\t{mso-style-name:SampleIO;\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:16.4pt;\n\tmargin-bottom:.0001pt;\n\tfont-size:12.0pt;\n\tfont-family:\"Courier 10 Pitch\";}\n.MsoChpDefault\n\t{font-size:10.0pt;}\n /* Page Definitions */\n @page Section1\n\t{size:8.5in 11.0in;\n\tmargin:1.0in 1.0in 1.0in 1.0in;}\ndiv.Section1\n\t{page:Section1;}\n /* List Definitions */\n ol\n\t{margin-bottom:0in;}\nul\n\t{margin-bottom:0in;}\n--\u003e\n\u003c/style\u003e \n \u003cp class\u003d\"MsoNormal\"\u003eRecently, a piece of text has been circulating on social media. It contains a paragraph where \u003cb\u003ethe first and last letters of each word remain unmodified and all the characters in the middle are reordered freely.\u003c/b\u003e Yet amazingly, many people can still read it without any hiccups.\u003c/p\u003e \n \u003cp class\u003d\"MsoNormal\"\u003eNow you are given a task similar to this in your final project: \u003cb\u003eGiven a sentence and a dictionary of words, how many different sentences can you find that could potentially be mapped to the same encoding?\u003c/b\u003e \u003c/p\u003e "}},{"title":"Input","value":{"format":"HTML","content":" \n \u003cp class\u003d\"MsoNormal\"\u003eInput starts with an integer \u003cb\u003eT (\u003c/b\u003e\u003cb\u003e≤ 20)\u003c/b\u003e, denoting the number of test cases.\u003c/p\u003e \n \u003cp class\u003d\"MsoNormal\"\u003eEach case starts with a line containing the number \u003cb\u003en (0 ≤ n ≤ 10000)\u003c/b\u003e of words in the dictionary, which are printed on the following \u003cb\u003en\u003c/b\u003e lines. After this, there is a line containing the number \u003cb\u003em (0 ≤ m ≤ 10000)\u003c/b\u003e of sentences that should be tested with the preceding dictionary and then \u003cb\u003em\u003c/b\u003e lines containing those sentences. The sentences consist of letters from \u003cb\u003ea\u003c/b\u003e to \u003cb\u003ez\u003c/b\u003e, \u003cb\u003eA\u003c/b\u003e to \u003cb\u003eZ\u003c/b\u003e and spaces only and have a maximal length of \u003cb\u003e10000\u003c/b\u003e characters. For each word in the dictionary a limitation of \u003cb\u003e100\u003c/b\u003e characters can be assumed. The words are case sensitive. In any case, total number of characters in the sentences will be at most \u003cb\u003e10\u003csup\u003e5\u003c/sup\u003e\u003c/b\u003e. And total characters in the dictionary will be at most \u003cb\u003e10\u003csup\u003e5\u003c/sup\u003e\u003c/b\u003e.\u003c/p\u003e \n "}},{"title":"Output","value":{"format":"HTML","content":" \n \u003cp class\u003d\"MsoNormal\"\u003eFor each case, print the case number first. Then for each sentence, output the number of sentences that can be formed on an individual line. Result fits into 32 bit signed integer.\u003c/p\u003e \n "}},{"title":"Sample Input","value":{"format":"HTML","content":" \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003e1\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003e8\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003ebaggers\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003ebeggars\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003ein\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003ethe\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003eblowed\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003ebowled\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003ebarn\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003ebran\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003e1\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003ebeggars bowled in the barn\u003c/span\u003e\u003c/p\u003e "}},{"title":"Sample Output","value":{"format":"HTML","content":" \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003eCase 1:\u003c/span\u003e\u003c/p\u003e \u003cp class\u003d\"MsoNoSpacing\"\u003e\u003cspan style\u003d\"font-family:\u0026quot;Courier New\u0026quot;\"\u003e8\u003c/span\u003e\u003c/p\u003e "}},{"title":"Note","value":{"format":"HTML","content":" \n \u003cp class\u003d\"MsoNormal\"\u003eDataset is huge, use faster I/O methods.\u003c/p\u003e \n "}}]}