﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _11.Logs_Aggregator
{
    public class LogsAggregator
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            var usersInfo = new SortedDictionary<string, SortedDictionary<string, int>>();

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                string user = input[1];
                string ip = input[0];
                int duration = int.Parse(input[2]);

                if (!usersInfo.ContainsKey(user))
                {
                    usersInfo.Add(user, new SortedDictionary<string, int>());
                }

                if (!usersInfo[user].ContainsKey(ip))
                {
                    usersInfo[user].Add(ip, 0);
                }
                usersInfo[user][ip] += duration;
            }

            foreach (var user in usersInfo)
            {
                Console.Write($"{user.Key}: {user.Value.Values.Sum()} ");
                Console.Write("[");

                foreach (var ip in user.Value)
                {
                    if (ip.Key != user.Value.Keys.Last())
                    {
                        Console.Write($"{ip.Key}, ");
                    }
                    else
                    {
                        Console.Write($"{ip.Key}");
                    }
                }
                Console.Write("]");
                Console.WriteLine();
            }

        }
    }
}
