// Arup Guha
// 9/10/04
// Solution to Books problem for 9/11/04 Practice

import java.io.*;

public class books {

  public static void main(String[] args) throws IOException {

    BufferedReader fin=new BufferedReader(new FileReader("books.in"));

    String[] books = new String[30];
    int index = 0, length;

    // Read in all the words.
    while (fin.ready()) {
      books[index] = fin.readLine();
      index++;
    }
    length = index; // Store the total number of words.

    sort(books, length);
    print(books, length);

  }

  public static void sort(String[] words, int length) {

    int i,j;

    // Do an insertion sort of words based on perm.
    for (i=1; i<length; i++) {
      j = i;

      // Insert the current element.
      while (j>0 && comesBefore(words[j], words[j-1])) {
        String temp = words[j-1];
        words[j-1] = words[j];
        words[j] = temp;
        j--;
      }
    }
  }

  // Returns true if and only if the TITLE of a comes before the
  // TITLE of b.
  public static boolean comesBefore(String word1, String word2) {

    int endindex1 = word1.indexOf('b');
    int endindex2 = word2.indexOf('b');
    String a = word1.substring(0, endindex1);
    String b = word2.substring(0, endindex2);

    int i = 0;

    // Skip over equal characters.
    while (i < a.length() && i < b.length() && a.charAt(i) == b.charAt(i))
      i++;

    // Check the case that a word is "done"
    if (i == a.length())
      return true;
    if (i == b.length())
      return false;

    // Otherwise, compare the first non-matching characters...
    return (a.charAt(i) < b.charAt(i));

  }


  public static void print(String[] words, int length) {

    // Determine the longest title.
    int i, j, maxlen = 0;
    for (i=0; i<length; i++)
      if (words[i].length() > maxlen)
        maxlen = words[i].length();

    // Loop through the column length.
    for (i=0; i<maxlen; i++) {

      // Loop through each title.
      for (j=0; j<length; j++) {

        // Print out the ith character in the jth book title, first
        // checking if the jth book title is that long.
        if (i < words[j].length())
          System.out.print(words[j].charAt(i)+" ");
        else
          System.out.print("  ");
      }
      System.out.println();
    }
  }

}
