SBANK - Sorting Bank Accounts

In one of the internet banks thousands of operations are being performed every day. Since certain customers do business more actively than others, some of the bank accounts occur many times in the list of operations. Your task is to sort the bank account numbers in ascending order. If an account appears twice or more in the list, write the number of repetitions just after the account number. The format of accounts is as follows: 2 control digits, an 8-digit code of the bank, 16 digits identifying the owner (written in groups of four digits), for example (at the end of each line there is exactly one space):

30 10103538 2222 1233 6160 0142 

Banks are real-time institutions and they need FAST solutions. If you feel you can meet the challenge within a very stringent time limit, go ahead! A well designed sorting algorithm in a fast language is likely to succeed.

Input


t [the number of tests <= 5]
n [the number of accounts<= 100 000]
[list of accounts]
[empty line]
[next test cases]

Output


[sorted list of accounts with the number of repeated accounts]
[empty line]
[other results]

Example

Input:
2
6
03 10103538 2222 1233 6160 0142 
03 10103538 2222 1233 6160 0141 
30 10103538 2222 1233 6160 0141 
30 10103538 2222 1233 6160 0142 
30 10103538 2222 1233 6160 0141 
30 10103538 2222 1233 6160 0142 

5
30 10103538 2222 1233 6160 0144 
30 10103538 2222 1233 6160 0142 
30 10103538 2222 1233 6160 0145 
30 10103538 2222 1233 6160 0146 
30 10103538 2222 1233 6160 0143 

Output:
03 10103538 2222 1233 6160 0141 1
03 10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0141 2
30 10103538 2222 1233 6160 0142 2

30 10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0143 1
30 10103538 2222 1233 6160 0144 1
30 10103538 2222 1233 6160 0145 1
30 10103538 2222 1233 6160 0146 1

Added by:mima
Date:2004-06-01
Time limit:7s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6 VB.NET
Resource:-

hide comments
2022-10-11 04:38:19
QWQ
2021-11-10 08:48:45
AC in zero go
2021-09-15 05:26:22 Henrique
LSD radix sort alone gives 0.12 seconds
2021-05-28 08:01:57
use getline and long long int in map got many wa due to this:(
2021-02-22 01:41:47 Rafail Loizou
This should have been a challenge problem instead and the people that thought of tries instead of maps or conventional string comparing would get more points than the others. But I guess it had to be classical (Well back in 2004 it makes sense)
2020-12-28 22:44:15
AC in one go :P no need to use any maps
2020-10-07 09:18:48
just set (of string) and map

Last edit: 2020-10-07 09:19:13
2020-09-24 13:07:53
Use cin.ignore() before your input string loop
2020-08-09 13:03:45
Sort->use pair->enjoy:)
2020-06-25 12:19:31
Why people using map just print them
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.