/*
 * Calculate the longest string in the file and print it out
 */

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Scanner;

/**
 *
 * @author Kyle Z
 */
public class Main {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        File f = new File(args[0]);
        BufferedReader read = new BufferedReader(new FileReader(f));
        HashMap<Integer, String> hmap = new HashMap<Integer, String>();
        FastSort change = new FastSort();

        String line;
        int[] topNumbers = null; // the elements to the array will be the keys to the hashmap
        int amount = 0;
        if ((line = read.readLine()) != null) {
            amount = Integer.parseInt(line);
            topNumbers = new int[amount];
        }
        int count = 0;
        
        while ((line = read.readLine()) != null) {
            if (count <= (amount - 1)) {
                topNumbers[count] = line.length();  // fill the array
                
                if (count == (amount - 1)) { // once the array is full
                    //sort the list
                    change.sort(topNumbers);
                }
            }
            else{   // check the bottom of the array
                if (line.length() > topNumbers[0]) { // look up the list till false
                    //replace
                    topNumbers[0] = line.length();
                    //sort
                    change.sort(topNumbers);
                }
            }
            hmap.put(line.length(), line);  // store pair in map
            count++;
        }/////////////////in the end flip the array & print
        //do this in a for loop here AND REMEMBER TO PRINT THE ELEMENTS OF THE HASHMAP
        for (int i = (amount - 1); i >= 0; i--) {
            System.out.println(hmap.get(topNumbers[i]));
        }
    }
}

/*
 * This class will contain a quicksort method
 */

class FastSort {
    private int array[];
    private int length;
 
    public void sort(int[] input) {
        if (input == null || input.length == 0) {
            return;
        }
        this.array = input;
        length = input.length;
        quickSort(0, length - 1);
    }
 
    private void quickSort(int lowerIndex, int higherIndex) {
        int i = lowerIndex;
        int j = higherIndex;
        // pivot is middle index number
        double pivot = array[lowerIndex+(higherIndex-lowerIndex)/2];
        // store two arrays
        while (i <= j) {
            while (array[i] < pivot) {
                i++;
            }
            while (array[j] > pivot) {
                j--;
            }
            if (i <= j) {
                exchangeNumbers(i, j);
                //move index on both sides
                i++;
                j--;
            }
        }
        // call quickSort() recursively
        if (lowerIndex < j)
            quickSort(lowerIndex, j);
        if (i < higherIndex)
            quickSort(i, higherIndex);
    }
 
    private void exchangeNumbers(int i, int j) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}