Problem C: String Connection
Time limit: 2 second
Problem Description
Write a program to connect strings. Given two strings s1 and s2,
the connection of s1 and s2 is the shortest string that has s1 as the
prefix (beginning of a string), and s2 as the suffix (the ending of a
string). For example if we connect "birthday" and "daylight" we will
get "birthdaylight". For another example, if we connect "birthdays"
and "daylight", we will get "birthdaysdaylight". Now given N strings,
$S_1,... S_N$, which consist of lowercase letters, please output the
result of connecting s1 and s2, then connecting to s3, and so on.
Input
The first line contains a positive integer N indicating the number
of test cases. Each case contains a positive integer M, where 2 < M
<= 30. The next M lines contain the strings $S_1$ to $S_m$. The length of
all strings is between 1 and 100.
Output
You should output the length and the string of connecting s1,
and s2, then s3, and so on.
Sample Input:
2
3
abc
bcdef
g
2
news
paper
Sample Output:
7
abcdefg
9
newspaper