#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int tinf = (int)1e9 + 7;
const long long inf = (long long)1e18 + 7;
const int N = 2e5 + 5;
const long long M = 1e9 + 7;
const int rx[4] = {1, 0, -1, 0};
const int ry[4] = {0, 1, 0, -1};
int tmin[35][N * 4], tmax[35][N * 4], a[N][6], b[35][N];
inline void buildMax(int v, int tl, int tr, int z) {
  if (tl == tr) {
    tmax[z][v] = b[z][tl];
  } else {
    int tm = ((tl + tr) >> 1), u = v + v;
    buildMax(u, tl, tm, z);
    buildMax(u + 1, tm + 1, tr, z);
    tmax[z][v] = max(tmax[z][u], tmax[z][u + 1]);
  }
}
inline void buildMin(int v, int tl, int tr, int z) {
  if (tl == tr) {
    tmin[z][v] = b[z][tl];
  } else {
    int tm = ((tl + tr) >> 1), u = v + v;
    buildMin(u, tl, tm, z);
    buildMin(u + 1, tm + 1, tr, z);
    tmin[z][v] = min(tmin[z][u], tmin[z][u + 1]);
  }
}
inline int resMax(int v, int tl, int tr, int l, int r, int z) {
  if (l > r) {
    return -tinf;
  }
  if (tl == l && tr == r) {
    return tmax[z][v];
  }
  int tm = ((tl + tr) >> 1), u = v + v;
  return max(resMax(u, tl, tm, l, min(tm, r), z),
             resMax(u + 1, tm + 1, tr, max(tm + 1, l), r, z));
}
inline int resMin(int v, int tl, int tr, int l, int r, int z) {
  if (l > r) {
    return tinf;
  }
  if (tl == l && tr == r) {
    return tmin[z][v];
  }
  int tm = ((tl + tr) >> 1), u = v + v;
  return min(resMin(u, tl, tm, l, min(tm, r), z),
             resMin(u + 1, tm + 1, tr, max(tm + 1, l), r, z));
}
inline void update(int v, int tl, int tr, int pos, int z) {
  if (tl == tr) {
    tmin[z][v] = b[z][pos];
    tmax[z][v] = b[z][pos];
  } else {
    int tm = ((tl + tr) >> 1), u = v + v;
    if (pos <= tm) {
      update(u, tl, tm, pos, z);
    } else {
      update(u + 1, tm + 1, tr, pos, z);
    }
    tmin[z][v] = min(tmin[z][u], tmin[z][u + 1]);
    tmax[z][v] = max(tmax[z][u], tmax[z][u + 1]);
  }
}
signed main() {
  {
    ios ::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  }
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      cin >> a[i][j];
    }
  }
  for (int z = 0; z < 32; ++z) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < k; j++) {
        if ((z | (1 << j)) == z) {
          b[z][i] += a[i][j];
        } else
          b[z][i] += -a[i][j];
      }
    }
    buildMax(1, 0, n - 1, z);
    buildMin(1, 0, n - 1, z);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 2) {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      int ans = 0;
      for (int j = 0; j < 32; j++) {
        ans = max(ans,
                  resMax(1, 0, n - 1, l, r, j) - resMin(1, 0, n - 1, l, r, j));
      }
      cout << ans << '\n';
    } else {
      int pos;
      cin >> pos;
      pos--;
      for (int j = 0; j < k; ++j) {
        cin >> a[pos][j];
      }
      for (int z = 0; z < 32; ++z) {
        b[z][pos] = 0;
        for (int j = 0; j < k; ++j) {
          if ((z | (1 << j)) == z) {
            b[z][pos] += a[pos][j];
          } else
            b[z][pos] += -a[pos][j];
        }
        update(1, 0, n - 1, pos, z);
      }
    }
  }
}
