Frequent Substrings

You are working for the R&D department of International Embedded Equipments Enterprise (IEEE). One day, your boss calls you up and tells this: “Yes, I think we should use the N-Gram Analysis for the project. What do you think??” “Ye...s, I also thought so...”, you replied. After the conversation, having no clue about what he said, you start searching the internet and find the following sentences. N-Grams are substrings of length N. N-Gram Analysis is a method of matching text, based on the statistical similarity of occurrences of N-Grams. N-Gram Analysis is used in research areas such as speech recognition, database interfacing, network communication etc. After going through the topic a few times and reading several articles, you figure out the main parts of the project you have to accomplish. One of the parts required you to do this: Given a string S, you have to find the most frequently occurring N-Gram in S. Since you found this part interesting, you decide to complete it soon. Note that the occurrences can partially overlap. That is, the string ‘bcbcbc’ has two occurrences of the substring ‘cbc’. Input Input consists of several test cases. Each test case begins with a line specifying the string S. S will contain no more than 1,000 characters. S can contain any of the printable ASCII characters. Capitalization should be ignored while finding the N-Grams. The next line specifies an integer T. Next T lines give the values for N, 0 < N ≤ Length(S). Output For each test case, output T lines specifying the number of occurrences of the N-Gram followed by the N-Gram itself separated by exactly one space. If there are several such N-Grams, output the least lexicographical one, compared in terms of ASCII values. Note: Given two strings a = and b = over the same alphabet V, we say that a is lexicographically less than b if there exist an integer j, 0 ≤ j ≤ m, so that ai = bi foralli=0,1...j−1andaj <bj. Sample Input In theory, there is no difference between theory and practice, but in practice, there is. 2 4 9 Sample Output 4 the 2 practice