let () =
  let rec read () =
    let n = read_int () in
    if n = 0 then ()
    else
      begin
        let hash = Hashtbl.create 4000 in
        let rec loop list = function
            0 -> list
          | i ->
             let line = read_line ()
                        |> Str.split (Str.regexp " ")
                        |> List.map int_of_string
                        |> Array.of_list in
             let (id,q,p) = (line.(0),line.(1),line.(2)) in
             if Hashtbl.mem hash id then
               begin
                 let x = (Hashtbl.find hash id)+p*q in
                 Hashtbl.replace hash id x;loop list (i-1)
               end
             else
               begin
                 let x = p*q in
                 Hashtbl.add hash id x;loop (id::list) (i-1)
               end
        in
        let cnt = ref 0 in
        let f x =
          let value = Hashtbl.find hash x in
          if value >= 1000000 then
            begin
              Printf.printf "%d\n" x;cnt:=!cnt+1
            end
        in
        List.iter f (loop [] n |> List.rev);
        if !cnt = 0 then Printf.printf "NA\n" else ();
        read ()
      end
  in
  read ()
;;