#K35967. Taco Subsequence Game

    ID: 25649 Type: Default 1000ms 256MiB

Taco Subsequence Game

Taco Subsequence Game

You are given a number of test cases. For each test case, you are given an integer \(n\) followed by \(n\) strings. A string \(a\) is said to be a subsequence of string \(b\) if it can be derived from \(b\) by deleting some or no characters without changing the order of the remaining characters.

For each test case, define the "win count" for a given string as the number of other strings in the same test case for which it is a subsequence. Note that every string has a minimum win count of 1 (counting itself). Your task is to compute the maximum win count among all strings in each test case.

Example: Consider the test case with \(n = 3\) and strings: "abc", "ab", and "a". Here, "a" is a subsequence of both "abc" and "ab" so its win count is 2, while the others have win counts of 0 and 1 respectively (excluding the self count, then taking the baseline 1). Hence, the answer is 2.

inputFormat

The input is read from stdin and follows this format:

  1. An integer \(T\) denoting the number of test cases.
  2. For each test case:
    • An integer \(n\) representing the number of strings.
    • \(n\) lines each containing a non-empty string.

Sample Input:

7
3
abc
ab
a
4
rock
paper
scissors
string
2
aaa
aa
1
abcd
3
xyz
xy
x
3
abc
def
ghi
5
a
aa
aaa
aaaa
aaaaa

outputFormat

For each test case, output the maximum win count on a separate line to stdout.

Sample Output:

2
1
1
1
2
1
4
## sample
7
3
abc
ab
a
4
rock
paper
scissors
string
2
aaa
aa
1
abcd
3
xyz
xy
x
3
abc
def
ghi
5
a
aa
aaa
aaaa
aaaaa
2

1 1 1 2 1 4

</p>