#C3352. Longest Common Prefix Length

    ID: 46770 Type: Default 1000ms 256MiB

Longest Common Prefix Length

Longest Common Prefix Length

In this problem, you are given several test cases. Each test case consists of a list of strings (for example, dish names). Your task is to determine the length of the longest common prefix among all strings in a test case. Formally, if (P) is the longest common prefix of the given strings, you need to output ( |P| ), where ( |P| ) represents the length of (P) in (\LaTeX) format.

Note: If there is no common prefix, the answer is 0.

You need to read the input from standard input and write your answers to standard output. The input begins with an integer (T) denoting the number of test cases. For each test case, the first line contains an integer (N) representing the number of strings, followed by (N) lines each containing a non-empty string.

inputFormat

The input is read from stdin and has the following format:

( T )
( N_1 )
string_1
string_2
...
string_{N_1}
( N_2 )
string_1
... and so on for (T) test cases.

outputFormat

For each test case, output a single line containing one integer – the length of the longest common prefix among the given strings. The output must be written to stdout.## sample

3
3
spaghetti
spanakopita
spicy
2
pizza
pizzicato
4
applepie
applejuice
applecrumble
appletart
2

4 5

</p>