// Arup Guha
// 12/3/2016
// Written to illustrate custom sorting by implementing a Comparator, solves same problem as customsort.java

import java.util.*;

public class customsort2 {

	public static void main(String[] args) {

		// Read in number of students.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();

		// Read in student names.
		String[] list = new String[n];
		for (int i=0; i<n; i++)
			list[i] = stdin.next();
			
		// Sort array of Strings by giving it the Comparator to use. The Comparator constructor takes in the compare method.
		Arrays.sort(list, new Comparator<String>(){
			public int compare(String a, String b) {
				if (a.length() != b.length()) return a.length()-b.length();
				return a.compareTo(b);
			}

		});

		// Print it.
		for (int i=0; i<n; i++)
			System.out.println(list[i]);
	}
}