#include <bits/stdc++.h>

using namespace std;

#define SELF_TEST

const int N = 2000, P = N + 1; int a[ N ][ N ];

typedef long long ll;  ll sum[ P ][ P ];

typedef long double ldbl;

typedef chrono::high_resolution_clock Clock_t;

typedef Clock_t::time_point      time_point_t;

time_point_t Now() { return Clock_t::now(); }

struct Timer_t
{
    time_point_t start_time;

    Timer_t() : start_time( Now() ) {}

    typedef long double ldbl;

    typedef chrono::nanoseconds nanosec_t;

    ll elaped_time()
    {
        nanosec_t timer = chrono::duration_cast< nanosec_t >( Now() - start_time );

        return timer.count();
    }
};

struct random_t: mt19937_64
{
    random_t() : mt19937_64( Clock_t::now().time_since_epoch().count() ) {}

    int random( int MIN, int MAX )
    {
        ll x_min = MIN, x_max = MAX, interval = x_max - x_min + 1, number = (*this)();

        if ( number < 0 )
            number += LLONG_MAX;

        return x_min + ( number % interval );
    }

} mt;

inline string time_to_str( const string &prefix, ll elapsed_time )
{
    return prefix + " time " + to_string( elapsed_time ) + " msec.";
}

const string no_solution = "NIE";

struct plot_purchase_t
{
    ll elapsed_time, iterations, r, s, t; int test_case, k, l, n, a_min;

    void answer( Timer_t &timer, string solution )
    {
#ifdef SELF_TEST

        elapsed_time = timer.elaped_time() / 1000000LL,
        solution  = "test " + to_string( test_case ) + ": " + solution,
        solution += ", " + time_to_str( "elapsed", elapsed_time );

#endif

        cout << solution;

#ifdef SELF_TEST

        cout << endl;

#endif
    }

    void solve()
    {
        Timer_t timer; int x0, y0, x1, y1, x2, y2;

        for( y0 = 0, y1 = 1; y0 < n; y0 = y1++ )
            for( x0 = 0, x1 = 1; x0 < n; x0 = x1++ )
            {
                auto &z = sum[ y1 ][ x1 ];

                z  =   a[ y0 ][ x0 ],
                z += sum[ y0 ][ x1 ],
                z += sum[ y1 ][ x0 ],
                z -= sum[ y0 ][ x0 ];
            }


        if ( sum[ n ][ n ] < k or a_min > l )
            return answer( timer, no_solution );

        if ( sum[ n ][ n ] <= l )
            return answer( timer, "1 1 " + to_string( n ) + " " + to_string( n ) );

        for( y0 = 0, y1 = 1; y0 < n; y0 = y1++ )
            for( x0 = 0, x1 = 1; x0 < n; x0 = x1++ )
                if ( a[ y0 ][ x0 ] <= l )
                {
                    for( r = sum[ y0 ][ x0 ], y2 = y1; y2 <= n; y2++ )
                        for( s = sum[ y2 ][ x0 ] - r, x2 = x1; x2 <= n; x2++ )
                            if ( ( iterations++, t = sum[ y2 ][ x2 ] - sum[ y0 ][ x2 ] - s ) > l )
                                break;
                            else
                                if ( t >= k )
                                {
                                    string solution =   to_string( y1 ) + ' ' +
                                                        to_string( x1 ) + ' ' +
                                                        to_string( y2 ) + ' ' +
                                                        to_string( x2 );
#ifdef SELF_TEST
                                    solution +=     "\nn = " +
                                                    to_string( n ) + ", k = " +
                                                    to_string( k ) + ", " +
                                                    to_string( iterations ) + " iteration(s), sum / k = " +
                                                    to_string( ldbl( t ) / ldbl( k ) );
#endif
                                    return answer( timer, solution );

                                }
                }

            return answer( timer, no_solution );
    }

    plot_purchase_t( int t = 0 ) :	elapsed_time( 0 ), iterations( 0 ),
			test_case( t ), a_min( INT_MAX )
    {

#ifdef SELF_TEST

          k = mt.random( 1, 1000000000 ),
          n = mt.random( 1, 2000 );


        for( int y0 = 0; y0 < n; y0++ )
            for( int x0 = 0; x0 < n; x0++ )
                a[ y0 ][ x0 ] = mt.random( 1, 2000000000 );

        a[ 1999 ][ 1999 ] = 200000001;
#else

        cin >> k >> n;

        for( int y0 = 0; y0 < n; y0++ )
            for( int x0 = 0; x0 < n; x0++ )
                cin >> a[ y0 ][ x0 ];

#endif

        memset( sum, 0, sizeof sum );

        for( int y0 = 0; y0 < n; y0++ )
            for( int x0 = 0; x0 < n; x0++ )
                a_min = min( a_min, a[ y0 ][ x0 ] );

       l = 2 * k, solve();
    }

};

template< typename T > struct data_analysis_t
{
    T min_value, max_value, sum; int count;

    data_analysis_t() : min_value( LLONG_MAX ), max_value( LLONG_MIN ),
                        sum( 0 ), count( 0 ) {}

    void add_value( T x )
    {
        min_value = min( min_value, x ),
        max_value = max( max_value, x ),
        sum      += x,
        count++;
    }

    ldbl avg_value() const
    {
        return ldbl( sum ) / ldbl( count );
    }

    friend ostream& operator << ( ostream &output, const data_analysis_t &x )
    {
        output << "avg " << ldbl( x.sum ) / ldbl( x.count ) << ", ",
        output << "min " << x.min_value << ", ",
        output << "max " << x.max_value;

        return output;
    }
};

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

#ifdef SELF_TEST

    int tests; cin >> tests; assert( tests > 0 );

    data_analysis_t< ll > elapsed_time, iterations, n, k;

    data_analysis_t< ldbl > s;

    for( int i = 0; i < tests; i++ )
    {
        plot_purchase_t problem( i );

        elapsed_time.add_value( problem.elapsed_time ),
          iterations.add_value( problem.iterations   ),
                   n.add_value( problem.n            ),
                   k.add_value( problem.k            ),
                   s.add_value( ldbl( problem.t ) / ldbl( problem.k ) );
    }

    cout << "elapsed time: " << elapsed_time << endl,
    cout << "iteration(s): " << iterations << endl,
    cout << "n           : " << n << endl,
    cout << "k           : " << k << endl,
    cout << "sum / k     : " << s << endl;

#else

    plot_purchase_t problem; problem.solve();

#endif
}
