#include <stdio.h>
#include <set>
#include <algorithm>

using namespace std;

set < pair < int, pair < int, int > > > skup;

int v[ 101 ][ 101 ], n;

int main()
{
    freopen( "pentranje.in", "r", stdin );
    freopen( "pentranje.out", "w", stdout );

    scanf("%d", &n );

    for ( int i = 1; i <= n; i ++ )

        for ( int j = 1; j <= n; j ++ )
        {
            pair < int, pair < int, int > > t;

            scanf("%d", &t. first );

            t. second = make_pair( i, j );

            skup. insert( t );

            v[ i ][ j ] = t. first;
        }

    int q;
    scanf("%d", &q );

    while ( q -- )
    {
        int k;
        scanf("%d", &k );

        if ( k == 1 )
        {
            int x, y, tmax = -1;
            scanf("%d%d", &x, &y );

            for ( set < pair < int, pair < int, int > > > :: iterator i = skup. begin(); i -> first < v[ x ][ y ]; i ++ )

                if ( abs( i -> second. first - x ) + abs( i -> second. second - y ) > tmax ) tmax = abs( i -> second. first - x ) + abs( i -> second. second - y );

            printf("%d\n", tmax );
        }
        else
        {
            int x, y, vr;
            scanf("%d%d%d", &x, &y, &vr );

            skup. erase( make_pair( v[ x ][ y ], make_pair( x, y )));
            skup. insert( make_pair( vr, make_pair( x, y )));

            v[ x ][ y ] = vr;
        }
    }

    return 0;
}
