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

hide comments
anmol23: 2017-05-06 08:44:59

AC in one go with maps!

anurag_tangri: 2017-04-11 23:11:52

EASY AF :)

rohit9934: 2017-03-09 16:42:18

Its Logical,Use Map.Dont Forget to use
ios_base::sync_with_stdio(false);
cin.tie(NULL);
In C++.

nilabja16180: 2017-02-28 11:12:00

MAPS is key! AC in one GO!

cake_is_a_lie: 2017-02-14 14:38:24

Top time lol (#5 with 0.06s; #1 is 0.04s) using just simple fast I/O, encoding and std::sort.

scorpion_ajay: 2017-02-12 18:13:47

language based question, :(

swatantragupta: 2017-01-16 19:45:57

compilation error in c++14 ..accepted in c++5.1..

madhavgaba: 2017-01-16 18:32:10

even O(n^2) lexographical sorting won't take 7s......weak time limit

up79: 2016-12-28 21:19:13

finally 50th :)
getting compilation error in c++ 14 :(
but AC in c++ 5.1 :) don't know why !

vengatesh15: 2016-12-08 06:22:38

AC in 1go :-)


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:-