Problem:
Sorting Tuples

Write a program which reads $n$ items and sorts them. Each item has attributes $\{value, weight, type, date, name\}$ and they are represented by $\{$ integer, integer, upper-case letter, integer, string $\}$ respectively. Sort the items based on the following priorities.

first by value (ascending)

in case of a tie, by weight (ascending)

in case of a tie, by type (ascending in lexicographic order)

in case of a tie, by date (ascending)

in case of a tie, by name (ascending in lexicographic order)

Input

The input is given in the following format.

$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$

In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.

Output

Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.

Constraints

$1 \leq n \leq 100,000$

$0 \leq v_i \leq 1,000,000,000$

$0 \leq w_i \leq 1,000,000,000$

$t_i$ is a upper-case letter

$0 \leq d_i \leq 2,000,000,000,000$

$1 \leq $ size of $s_i \leq 20$

$s_i \ne s_j$ if $(i \ne j)$

Sample Input 1

5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree

Sample Output 1

100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black

Solution in Go (judge verdict: Accepted)

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"sort"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

type Item struct {
	v int
	w int
	t string
	d int
	s string
}

type Items []Item

func (p Items) Len() int {
	return len(p)
}

func (p Items) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Items) Less(i, j int) bool {
	if p[i].v == p[j].v {
		if p[i].w == p[j].w {
			if p[i].t == p[j].t {
				if p[i].d == p[j].d {
					return p[i].s < p[j].s
				} else {
					return p[i].d < p[j].d
				}
			} else {
				return p[i].t < p[j].t
			}
		} else {
			return p[i].w < p[j].w
		}
	}
	return p[i].v < p[j].v
}

func main() {
	scanner.Split(bufio.ScanWords)
	var points Items = []Item{}
	n := nextInt()
	for i := 0; i < n; i++ {
		v := nextInt()
		w := nextInt()
		t := nextString()
		d := nextInt()
		s := nextString()
		points = append(points, Item{v,w,t,d,s})
	}
	sort.Sort(points)
	for i := range points {
		fmt.Printf("%d %d %s %d %s\n", points[i].v, points[i].w, points[i].t, points[i].d, points[i].s)
	}
}