{"trustable":true,"sections":[{"title":"","value":{"format":"MD","content":"\u003chtml\u003e\n\u003cbody\u003e\nJARVIS(Just A Rather Very Intelligent System) has still many things to learn to become more intelligent. Tony Stark wants to teach Competitive Programming to it. So he starts directly with Strings and tells JARVIS about \u003cb\u003eLongest Common Prefix(LCP)\u003c/b\u003e of two strings. Also Tony gives JARVIS a set of strings \u003cb\u003eS\u003csub\u003e1\u003c/sub\u003e, S\u003csub\u003e2\u003c/sub\u003e, ..., S\u003csub\u003en\u003c/sub\u003e\u003c/b\u003e. JARVIS starts playing with those strings and comes up with a problem. The problem is as follows,\n\n\u003cbr\u003e\u003cbr\u003e\n\nIf \u003cb\u003eLCP\u003c/b\u003e of \u003cb\u003eX\u003csup\u003eth\u003c/sup\u003e\u003c/b\u003e and \u003cb\u003eY\u003csup\u003eth\u003c/sup\u003e\u003c/b\u003e strings is \u003cb\u003eL\u003c/b\u003e then how many times \u003cb\u003eL\u003c/b\u003e occures in the set as a substring of any string?\n\n\u003cbr\u003e\u003cbr\u003e\n\nJARVIS comes with many such \u003cb\u003eX\u003c/b\u003e\u0027s and \u003cb\u003eY\u003c/b\u003e\u0027s to Pepper. Being very busy, she asks you to tell the answers of the JARVIS\u0027 quesions. Can you help her answering the questions?\n\n\u003ch3\u003eInput\u003c/h3\u003e\nThe first line contains \u003cb\u003eN\u003c/b\u003e, the number of strings in the set.\u003cbr\u003e\nThe Next \u003cb\u003eN\u003c/b\u003e lines contain the strings of the given set.\u003cbr\u003e\nThe next line contains \u003cb\u003eQ\u003c/b\u003e, the number of questions.\u003cbr\u003e\nEach line of the next \u003cb\u003eQ\u003c/b\u003e lines contains \u003cb\u003eX\u003csub\u003ei\u003c/sub\u003e\u003c/b\u003e and \u003cb\u003eY\u003csub\u003ei\u003c/sub\u003e\u003c/b\u003e, the indexes(1-based) of the two strings of \u003cb\u003ei\u003csup\u003eth\u003c/sup\u003e\u003c/b\u003e question.\n\u003ch3\u003eOutput\u003c/h3\u003e\nFor each question, output on a separate line the answer of the question.\n\u003ch3\u003eConstraints\u003c/h3\u003e\n\u003cul\u003e\n\u003cli\u003e\u003cb\u003e1 ≤ \u003cb\u003eN\u003c/b\u003e ≤ 10\u003csup\u003e5\u003c/sup\u003e\u003c/b\u003e\u003cbr\u003e\n\u003cli\u003e\u003cb\u003e1 ≤ Length of \u003cb\u003eS\u003csub\u003ei\u003c/sub\u003e\u003c/b\u003e ≤ 10\u003csup\u003e5\u003c/sup\u003e\u003c/b\u003e\u003cbr\u003e\n\u003cli\u003e\u003cb\u003e1 ≤ \u003cb\u003eQ\u003c/b\u003e ≤ 10\u003csup\u003e5\u003c/sup\u003e\u003c/b\u003e\u003cbr\u003e\n\u003cli\u003e\u003cb\u003e1 ≤ \u003cb\u003eX\u003csub\u003ei\u003c/sub\u003e\u003c/b\u003e ≤ \u003cb\u003eY\u003csub\u003ei\u003c/sub\u003e\u003c/b\u003e ≤ \u003cb\u003eN\u003c/b\u003e\u003c/b\u003e\u003cbr\u003e\n\u003cli\u003eSum of lengths of all strings ≤ 5*10\u003csup\u003e5\u003c/sup\u003e\u003c/b\u003e\u003cbr\u003e\n\u003cli\u003eStrings contain only lower case letters.\n\u003c/ul\u003e\n\u003ch3\u003eExample\u003c/h3\u003e\n\u003cb\u003eInput:\u003c/b\u003e\n\u003cbr\u003e\n4\u003cbr\u003e\nababa\u003cbr\u003e\naba\u003cbr\u003e\nabcd\u003cbr\u003e\ncbab\u003cbr\u003e\n3\u003cbr\u003e\n1 2\u003cbr\u003e\n2 3\u003cbr\u003e\n1 4\u003cbr\u003e\n\u003cbr\u003e\n\u003cb\u003eOutput:\u003c/b\u003e\n\u003cbr\u003e\n3\u003cbr\u003e\n5\u003cbr\u003e\n0\u003cbr\u003e\n\u003ch3\u003eExplanation\u003c/h3\u003e\nFor \u003cb\u003equery 1\u003c/b\u003e, LCP \u003cb\u003eL\u003c/b\u003e is \u003cb\u003eaba\u003c/b\u003e that occures 2 times in \u003cb\u003eababa\u003c/b\u003e, once in \u003cb\u003eaba\u003c/b\u003e.\u003cbr\u003e\nFor \u003cb\u003equery 3\u003c/b\u003e, LCP \u003cb\u003eL\u003c/b\u003e is an empty string so the answer is \u003cb\u003e0\u003c/b\u003e.\u003cbr\u003e \n\u003c/body\u003e\n\u003c/html\u003e"}}]}