// Arup Guha
// 1/6/2024
// Solution to CS 2 Spring 2024 Kattis Problem #1: Dyslectionary
// https://open.kattis.com/problems/dyslectionary

import java.util.*;

public class dyslectionary {

	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		boolean first = true;
		
		// Keep going until no more.
		while (stdin.hasNext()) {
		
			// Initialize list.
			ArrayList<term> list = new ArrayList<term>();
			term.resetmaxLen();
			String line = stdin.nextLine().trim();
			
			// Annoying knowing when to stop.
			while (line.length() != 0) {
				list.add(new term(line));
				
				if (stdin.hasNext())
					line = stdin.nextLine().trim();
				else
					break;
			}
			
			// Sort it!
			Collections.sort(list);
			
			// Also annoying...
			if (!first) System.out.println();
			
			// Print list sorted.
			for (int i=0; i<list.size(); i++)
				System.out.println(list.get(i));
		
			// So we go blank lines in the future.
			first = false;
		}
	}
}

class term implements Comparable<term> {
	
	private int n;
	private char[] orig;
	private String flip;
	private static int maxLen;
	
	public term(String s) {
		
		// How I want to store this.
		orig = s.toCharArray();
		n = orig.length;
		
		// Copy in reverse.
		char[] tmp = new char[n];
		for (int i=0; i<n; i++)
			tmp[i] = orig[n-1-i];
		flip = new String(tmp);
		
		// Update for the class.
		maxLen = Math.max(maxLen, n);
	}
	
	// Allows us to reset for a new case.
	public static void resetmaxLen() {
		maxLen = 0;
	}
	
	// This is all they want.
	public int compareTo(term other) {
		return flip.compareTo(other.flip);
	}
	
	public String toString() {
		
		int pad = maxLen - n;
		
		// Since small, we'll do inefficiently.
		String res = "";
		for (int i=0; i<pad; i++)
			res = res + " ";
		
		// String with correct padding.
		return res + new String(orig);
	}
}