{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"As you probably know, the human information processor is a wonderful text recognizer that can handle even sentences that are garbled like the following:\n\n**The ACM Itrenntaoial Clloegaite Porgarmmnig Cnotset (IPCC) porvdies clolgee stuetnds wtih ooppriuntetiis to itnrecat wtih sutednts form ohetr uinevsrtieis.**\n\nPeople have claimed that understanding these sentences works in general when using the following rule: The first and last letters of each word remain unmodified and all the characters in the middle can be reordered freely. Since you are an ACM programmer, you immediately set on to write the following program: Given a sentence and a dictionary of words, how many different sentences can you find that could potentially be mapped to the same encoding?\n\n"}},{"title":"Input","value":{"format":"MD","content":"Input starts with an integer **T (\u0026#8804; 20)**, denoting the number of test cases.\n\nEach case starts with a line containing the number **n (0 \u0026#8804; n \u0026#8804; 10000)** of words in the dictionary, which are printed on the following **n** lines. After this, there is a line containing the number **m (0 \u0026#8804; m \u0026#8804; 10000)** of sentences that should be tested with the preceding dictionary and then **m** lines containing those sentences.\n\nThe sentences consist of letters from **a** to **z**, **A** to **Z** and spaces only and have a maximal length of **10000** characters. For each word in the dictionary a limitation of **100** characters can be assumed. The words are case sensitive. In any case, total number of characters in the sentences will be at most **10\u003csup\u003e5\u003c/sup\u003e**. And total characters in the dictionary will be at most **10\u003csup\u003e5\u003c/sup\u003e**.\n\n"}},{"title":"Output","value":{"format":"MD","content":"For 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.\n"}},{"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\n8\nbaggers\nbeggars\nin\nthe\nblowed\nbowled\nbarn\nbran\n1\nbeggars bowled in the barn\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase 1:\n8\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"Note","value":{"format":"MD","content":"Dataset is huge, use faster I/O methods."}}]}