#K61607. User Activity Score Calculator

    ID: 31347 Type: Default 1000ms 256MiB

User Activity Score Calculator

User Activity Score Calculator

In this problem, you are given several test cases. Each test case contains a number of activity logs. Each log is a record of a user’s action in the system in the form ' '. There are three types of activities: (Post), (Comment), and (Like) with scores (5), (3), and (1) respectively. Your task is to compute the total score for each user in every test case and then sort the users by descending score; if two users have the same score, sort them in ascending lexicographical order. Finally, print the results for each test case in the specified format.

inputFormat

The first line of input contains an integer \(T\), representing the number of test cases. For each test case, the first line contains an integer \(N\) which indicates the number of activity logs. This is followed by \(N\) lines, each containing a user id and an activity type separated by a space.

outputFormat

For each test case, first output an integer \(M\) on a new line which represents the number of users with recorded activities. Then, output \(M\) lines where each line contains a user id and the corresponding total score (separated by a space). The users must be sorted by their total scores in descending order. In case of a tie in scores, the user ids should be sorted in ascending lexicographical order. If a test case has no activity logs (i.e. \(N = 0\)), simply output a line with 0.

## sample
5
5
Alice Post
Bob Comment
Alice Like
Alice Comment
Bob Post
4
Eve Like
Charlie Post
Charlie Comment
Eve Post
3
Alice Post
Bob Post
Charlie Post
1
Alice Post
0
2

Alice 9 Bob 8 2 Charlie 8 Eve 6 3 Alice 5 Bob 5 Charlie 5 1 Alice 5 0

</p>