#K80007. Most Common Phrase

    ID: 35434 Type: Default 1000ms 256MiB

Most Common Phrase

Most Common Phrase

You are given several test cases. In each test case, you are provided with N feedback statements and an integer L. Your task is to identify the most common phrase consisting of L consecutive words from the statements.

For each test case, you should:

  • Break each statement into words.
  • Extract every contiguous sequence (phrase) of L words.
  • Count the frequency of each phrase.
  • Among phrases with the highest frequency, choose the lexicographically smallest phrase.

Output the chosen phrase followed by a space and its frequency. All formulas in the statement are set in LaTeX format. For example, if a test case has N statements and a phrase length of L, for any phrase P the frequency can be expressed as:

$$freq(P)$$

There is at least one phrase in each test case.

inputFormat

The input begins with an integer T, the number of test cases, in stdin format.

Each test case starts with a line containing two integers N and L: the number of feedback statements and the phrase length (number of consecutive words), respectively.

This is followed by N lines, each a feedback statement.

Input Example:

2
3 2
this is a test statement
test this is a sample
statement this is not
2 3
we love coding
coding we love

outputFormat

For each test case, output a line containing the most common phrase followed by a space and its frequency. The output is written to stdout.

Output Example:

this is 3
coding we love 1
## sample
2
3 2
this is a test statement
test this is a sample
statement this is not
2 3
we love coding
coding we love
this is 3

coding we love 1

</p>