50172. Stairs

I'm a slow walker, but I never walk backwards.

Task Description

We want to construct stairs with given words.

We will print words one by one in one of the two directions, to the right and to the bottom. We start with the direction to the right, then we keep switching the direction for every word. If a word has its first letter the same as the last of the previous word, the two words share the letter. Otherwise, the new word start below the last letter of the previous word.

We need to fill the left side of the words with the character '*'. Note that using a two-dimensional array to store the whole output will cause runtime error.

Input Format

The input has at least one line. Each line has one word. Each word has $n$ lowercase letters, $3 \le n \le 30$. You must proceed all input until EOF.

Output Format

Output the stairs.

Sample Input 1

actions
speak
louder
than
words

Sample Output 1

actions
******p
******e
******a
******k
******louder
***********t
***********h
***********a
***********n
***********words

Sample Input 2

care
and
diligence
bring
luck

Sample Output 2

care
***a
***n
***diligence
***********b
***********r
***********i
***********n
***********g
***********luck

Strong Sample

Here are strong test data for you.

Discussion