// Arup Guha
// 4/3/2017
// Solution to 1991 UCF HS Contest Problem: The Alpabetizing Blues

import java.util.*;

public class books {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		
		// Maps title to the whole text on the spine of the book.
		TreeMap<String,String> titleMap = new TreeMap<String,String>();
		int maxlen = 0;

		// Read in each book. Store in map from title to whole string.
		while (stdin.hasNext()) {
			String book = stdin.nextLine();
			int tmpIdx = book.indexOf("by");
			String key = book.substring(0, tmpIdx-1);
			titleMap.put(key, book);
			maxlen = Math.max(maxlen, book.length());
		}

		// Will store grid here.
		ArrayList<String> list = new ArrayList<String>();
		
		// Extract one by one from the map.
		while (titleMap.size() > 0) {
			String title = titleMap.firstKey();
			list.add(titleMap.get(title));
			titleMap.remove(title);
		}

		// Copy results into here - put all spaces initially.
		char[][] grid = new char[maxlen][list.size()];
		for (int i=0; i<maxlen; i++) Arrays.fill(grid[i], ' ');

		// Here we copy the characters in, one by one going down.
		for (int i=0; i<list.size(); i++)
			for (int j=0; j<list.get(i).length(); j++)
				grid[j][i] = list.get(i).charAt(j);

		// Print the grid being careful to put a space between columns, but not after the last column.
		for (int i=0; i<grid.length; i++) {
			for (int j=0; j<grid[i].length; j++) {
				System.out.print(grid[i][j]);
				if (j < grid[i].length-1) System.out.print(" ");
			}
			System.out.println();
		}
	}
}