The Genographic Project is a research partnership between IBM and The National Geographic Society that analyzes DNA from hundreds of thousands of contributors to map how the Earth was populated.
As an IBM researcher, you have been asked to write a program that finds the commonalities among given snippets of DNA, which can then be correlated with survey information to identify new genetic markers.
A DNA base sequence is written by listing its nitrogen bases in the order they appear in the molecule. There are four bases: adenine (A), thymine (T), guanine (G), and cytosine (C). A 6-base DNA sequence could be written as TAGACC.
Given several DNA base sequences, find the longest run of consecutive bases (contiguous substring) that appears in every one of the sequences.
The first line contains a single integer $n$, the number of datasets. Each dataset consists of the following:
For each dataset, output the longest contiguous substring common to all of the given base sequences. If this longest common substring is shorter than three bases, output no significant commonalities instead. If several substrings share the same maximum length, output only the one that comes first in alphabetical order.