let rec push lst (n, s) = match lst with
  | [] -> (n, s) :: lst
  | (m, t) :: tl -> if n = m then (m, t+s) :: tl else (m, t) :: push tl (n, s)
let () =
  try
    while true do
      let init = Scanf.scanf "%d\n"
          (fun n -> if n = 0 then raise End_of_file
            else Array.to_list (Array.init n (fun _ -> Scanf.scanf "%d %d %d\n"
                             (fun e p q -> (e, p, q))))) in
      let second = List.map (fun (e, p, q) -> (e, p * q)) init in
      (* 社員ごと合計値を得たリスト作成する *)
      List.fold_left (fun lst (n, s) -> push lst (n, s)) [] second
      |> List.filter (fun (e, q) -> q >= 1000000)
      |> (fun lst -> if lst = [] then print_endline ("NA")
           else List.iter
               (fun (e, p) -> print_endline (string_of_int e)) lst)
    done
  with
  | End_of_file -> exit 0
