#include <cstdio>
#include <cstdlib>
#define MAXN            1000
#define MAXN2           MAXN*MAXN
#define lea2d(x,y,w)    ((x)+(y)*(w))

/* This is... pathetic... to the bone. */

int mat[MAXN2];

FILE * in, * out;
/*
int min_x_comp(const xy& newm, xy& old)
{
  if (!old.known || newm.x < old.x)
    old = newd;
  else if (newm.x == old.x) {
    if (newm.x 
}
*/

struct xy {
  int x, y;
};

inline int manhattan(const xy& one, const xy& two) {   
  return abs(two.x - one.x) + abs(two.y - one.y);
}

int main()
{
  in = fopen("pentranje.in", "r"); out = fopen("pentranje.out", "w");
  int N, pos;
  fscanf(in, "%d", &N);  
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      pos = lea2d(j, i, N);
      fscanf(in, "%d", mat + pos);
    }
  }
  
  int Q;
  fscanf(in, "%d", &Q);
  for (int i = 0; i < Q; ++i) {
    int type;
    fscanf(in, "%d", &type);
    if (type == 1) {
      int x, y;
      fscanf(in, "%d %d", &y, &x);
      --x; --y;
      
      int manh = -1;
      for (int j = 0; j < N; ++j) {
        for (int k = 0; k < N; ++k) {
          if (mat[lea2d(j, k, N)] < mat[lea2d(x, y, N)]) {
            xy a, b;
            a.x = x;
            a.y = y;
            b.x = j;
            b.y = k;
            int mymanh = manhattan(a,b);
            if (mymanh > manh)
              manh = mymanh;
          }
        }
      }
      
      fprintf(out, "%d\n", manh);
    } else {
      int x, y, ht;
      fscanf(in, "%d %d %d", &y, &x, &ht);
      --x; --y; ht;
      mat[lea2d(x, y, N)] = ht;
    }
  }

  int a, b;
  __asm__(
    "movl $5,%eax;"
    "movl $10,%ebx;"
    "addl %eax,%ebx;"
    "movl %ebx, -55(%ebp)"
    "");
fprintf(out, "%d %d", N, 1);

  fclose(in), fclose(out);
  return 0;
}
