def check_bingo(board)
  board.each do |l|
    stone = l.first
    return stone if l.all?{ |x| x == stone } && stone != '+'
  end

  return false
end

def choose_winner(board)
  diagonal_board = [[0,1,2].map{|x| board[x][x]}, [0,1,2].map{|x| board[x][2-x]}]
  [board, board.transpose, diagonal_board].each do |b|
    stone = check_bingo(b)
    return stone if stone
  end

  return "NA"
end

loop do
  board = [gets.chomp.chars]
  break if board[0] == ['0']
  board[1,2] = [nil, nil].map!{ gets.chomp.chars }
  
  puts choose_winner(board)
end