This page is still under construction.

Parts of this page are still being built. What you see may change.

Passwords

Time limit7sMemory limit128 MB

Summary
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 vv and ww. The two strings satisfy v∣w∣=w∣v∣v^{|w|} = w^{|v|}, which means that vv concatenated ∣w∣|w| times and ww concatenated ∣v∣|v| times give the same string, where ∣v∣|v| is the length of the string vv. For example, with v=abv = \mathtt{ab} and w=ababw = \mathtt{abab} you get v4=w2=ababababv^{4} = w^{2} = \mathtt{abababab}. The trivial case v=wv = w is not secure, so it is never used.

The two strings are hard to memorize, so the administrator hid them in a set of nn strings. The set contains two distinct strings xx and yy such that vv is a prefix of xx (x=vv′x = vv') and ww is a suffix of yy (y=w′wy = w'w).

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 TT.

Each test case begins with a line containing nn, the number of strings in the set. (2≤n≤2002 \le n \le 200)

Each of the next nn lines contains one string. Every string consists of lowercase English letters and its length is at most 20,00020{,}000.

Output

Your program writes to standard output. Print exactly one line for each test case.

Each line contains two integers ∣v∣|v| and ∣w∣|w|, where two distinct strings xx and yy of the set satisfy that vv is a prefix of xx, ww is a suffix of yy, v∣w∣=w∣v∣v^{|w|} = w^{|v|} and ∣v∣<∣w∣|v| < |w|. If two or more such pairs exist, print the one whose ∣v∣+∣w∣|v| + |w| is the greatest. Such a password pair is unique whenever it exists. If there is no such pair, print 0 0.

Examples2

  1. Example 1

    Input
    2
    3
    abcabe
    defg
    bcabab
    3
    abcdef
    ghijkl
    mnopqr
    
    Expected output
    2 4
    0 0
    
  2. Example 2

    Input
    2
    2
    aaaaaaaa
    baaa
    2
    abc
    cab
    
    Expected output
    2 3
    0 0