3101: Hassle Teacher

时间限制:1000 ms 内存限制:128 MB
上传者:
提交:29 通过:7

题目描述

The students in the ACM class have to re-select their partners, and every two students form a study group. In order to simply group them, the teacher sorts them according to each person's birthday, numbering them from 1 to n. If the birthday is the same, sort in the lexicographical order of the names.

The lexicographical order on the set of all these finite words orders the words as follows:

  • Given two different words of the same length, say $a = a_1a_2...a_k$ and $b = b_1b_2...b_k$, the order of the two words depends on the alphabetic order of the symbols in the first place i where the two words differ (counting from the beginning of the words): a < b if and only if $a_i < b_i$ in the underlying order of the alphabet A.
  • If two words have different lengths, the usual lexicographical order pads the shorter one with "blanks" (a special symbol that is treated as smaller than every element of A) at the end until the words are the same length, and then the words are compared as in the previous case.
Now let $a_i$ be the i-th classmate, then $a_i$ and $a_{n-i+1}$ must have a partner relationship. The students are very naughty. Even if some people don’t know the hour and minute of the birth time, they still report the content to the teacher.

Please help the teacher arrange each person’s partner. The teacher only needs the ranking of the students, so you need to output the names of the students after the ranking. In addition, the teacher wants to know how many minutes each person’s birthday differs from their partner’s birthday.

输入格式

Input contains multiple test cases.

The first line is an integer  $T(1\le T \le 100)$ ,indicating the number of test cases.

Each case begins with an integer $N(1\le N \le 100)$,indicating the number of students.

In the next n lines, each line describes the student’s name and birthday information. The input format of birthday is as follows: "YYYY-MM-DD hh:mm". Please see the sample for details.

Ensure that all students’ birthdays are between 1995 and 2010.

输出格式

Output n lines for each set of test data, the i line represents the name of the classmate $a_i$ and the number of minutes between the birthday of the partner.

输入样例 复制

2
2
Alice 2005-03-04 08:50
Bob 2005-03-05 09:00
4
Asuna 2007-09-30 08:29
Kirito 2008-10-07 10:47
Leafa 2009-04-19 22:56
Sinon 2009-08-21 13:39

输出样例 复制

Alice 1450
Bob 1450
Asuna 995350
Kirito 280089
Leafa 280089
Sinon 995350