using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int num;
            while ((num = int.Parse(Console.ReadLine())) != 0)
            {
                var result = Enumerable.Range(0, num)
                                       .Select(_ => Console.ReadLine())
                                       .Select(
                                           _ =>
                                           {
                                               var data =
                                                   _.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
                                                    .Select(int.Parse).ToList();
                                               return new { ID = data[0], Sales = data[1] * data[2] };
                                           })
                                           .GroupBy(_ => _.ID)
                                           .Select(_ => new { ID = _.Key, Sales = _.Select(x => x.Sales).Sum() });

                Console.WriteLine(result.Any() ? result.Select(_ => _.ID.ToString()).Aggregate((a, b) => a + Environment.NewLine + b) : "NA");
            }
        }
    }
}