import java.util.Scanner;
public class Main {
	static Nodd[] nn=new Nodd[26];
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()){
			int num = sc.nextInt();
			for(int i=0;i<num;i++){
				String str=sc.next();
				if(nn[str.charAt(0)-'a']==null){
					nn[str.charAt(0)-'a']=new Nodd(null,null,str);
				}else{
					set(nn[str.charAt(0)-'a'],new Nodd(null,null,str),1,str.charAt(0)-'a');
				}
			}
			for(int i=0;i<nn.length;i++){
				if(nn[i]!=null){
					System.out.println(nn[i].da);
					Nodd a=nn[i];
					while(a.next!=null){
						System.out.println(a.next.da);
						a=a.next;
					}
				}
			}
		}

	}
	static public void set(Nodd old,Nodd neww,int c,int zb){
		if(old.da.charAt(c)>neww.da.charAt(c)){
			neww.next=old;
			old.before=neww;
			if(nn[zb]==old){
				nn[zb]=neww;
			}
		}else if(old.da.length()<=c&&old.da.charAt(c)==neww.da.charAt(c)){
			set(old,neww,c+1,zb);
		}else{
			if(old.next==null){
				old.next=neww;
			}else{
				set(old.next,neww,1,zb);
			}
		}
	}
}
class Nodd{
	public Nodd before=null;
	public Nodd next=null;
	public String da=null;
	public Nodd(){
	}
	public Nodd(Nodd before,Nodd next,String da){
		this.before=before;
		this.next=next;
		this.da=da;
	}
}

结果稍微有点错误 不想改 谁帮忙指点下