arr = []
while true
    arr[0] = gets.chomp
    break if arr[0] == "0"
    arr[1] = gets.chomp
    arr[2] = gets.chomp

    result = "NA"
    [[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]],
     [[0, 0], [1, 0], [2, 0]], [[0, 1], [1, 1], [2, 1]], [[0, 2], [1, 2], [2, 2]],
     [[0, 0], [1, 1], [2, 2]], [[0, 2], [1, 1], [2, 0]]].each{|a, b, c|
        if arr[a[0]][a[1]] == arr[b[0]][b[1]] && arr[a[0]][a[1]] == arr[c[0]][c[1]] && arr[a[0]][a[1]] != "+"
            result = arr[a[0]][a[1]]
            break
        end
    }
    puts result
end

