
fun main(args:Array<String>):Unit {
    println(Array(readLine()!!.toInt()){
        val arg = readLine()!!.split(' ')
        val (value, weight) = arg.take(2).map(String::toInt)
        val date = arg[3].toLong()
        Goods(value, weight, Type(arg[2]), date, arg.last())
    }.sorted().joinToString("\n"))
}
class Type(val name:String):Comparable<Type>{
    override fun compareTo(other: Type): Int {
        return name.first().compareTo(other.name.first())
    }

    override fun toString(): String {
        return name
    }
}
fun <T, A:Comparable<A>> Pair<T, T>.compareWith(factor:Iterable<T.() -> A>):Int {
    val (a, b) = this
    return factor.map{func -> a.func().compareTo(b.func())}.find{it != 0} ?: 0
}
class Goods(val value:Int, val weight:Int, val type:Type, val date:Long, val name:String):Comparable<Goods>{
    override fun compareTo(other: Goods): Int {
        return if (value == other.value)
            if (weight == other.weight)
                if (type.compareTo(other.type) == 0)
                    if (date == other.date) name.compareTo(other.name)
                    else date.compareTo(other.date)
                else type.compareTo(other.type)
            else weight.compareTo(other.weight)
        else value.compareTo(other.value)
    }
    override fun toString(): String {
        return "$value $weight $type $date $name"
    }
}
