Passwords
Time limit7sMemory limit128 MB
Find the longest prefix length and suffix length from two distinct set strings whose repetitions coincide.
- Level
Hard8 of 10
- Topics
- String matching, String
- Solved
- No attempts yet
Problem
The secret server of ICPC (Inter-Continental Programming Company) uses two passwords and . The two strings satisfy , which means that concatenated times and concatenated times give the same string, where is the length of the string . For example, with and you get . The trivial case is not secure, so it is never used.
The two strings are hard to memorize, so the administrator hid them in a set of strings. The set contains two distinct strings and such that is a prefix of () and is a suffix of ().
Given the set of strings, write a program that finds the password pair.
Input
Your program reads from standard input. The first line contains the number of test cases .
Each test case begins with a line containing , the number of strings in the set. ()
Each of the next lines contains one string. Every string consists of lowercase English letters and its length is at most .
Output
Your program writes to standard output. Print exactly one line for each test case.
Each line contains two integers and , where two distinct strings and of the set satisfy that is a prefix of , is a suffix of , and . If two or more such pairs exist, print the one whose is the greatest. Such a password pair is unique whenever it exists. If there is no such pair, print 0 0.