#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
int tr[4 * N][33][2];
int a[N][6], k;
void bld(int x, int l, int r, int msk, bool rmin) {
  if (l == r) {
    for (int bit = 0; bit < k; bit++) {
      if ((msk >> bit) & 1)
        tr[x][msk][rmin] -= a[l][bit];
      else
        tr[x][msk][rmin] += a[l][bit];
    }
    return;
  }
  int m = (l + r) / 2;
  bld(2 * x, l, m, msk, rmin);
  bld(2 * x + 1, m + 1, r, msk, rmin);
  if (rmin)
    tr[x][msk][rmin] = min(tr[2 * x][msk][rmin], tr[2 * x + 1][msk][rmin]);
  else
    tr[x][msk][rmin] = max(tr[2 * x][msk][rmin], tr[2 * x + 1][msk][rmin]);
}
void upd(int x, int l, int r, int ul, int msk, bool rmin) {
  if (l > r || l > ul || r < ul) return;
  if (l == r) {
    tr[x][msk][rmin] = 0;
    for (int bit = 0; bit < k; bit++) {
      if ((msk >> bit) & 1)
        tr[x][msk][rmin] -= a[ul][bit];
      else
        tr[x][msk][rmin] += a[ul][bit];
    }
    return;
  }
  int m = (l + r) / 2;
  upd(2 * x, l, m, ul, msk, rmin);
  upd(2 * x + 1, m + 1, r, ul, msk, rmin);
  if (rmin)
    tr[x][msk][rmin] = min(tr[2 * x][msk][rmin], tr[2 * x + 1][msk][rmin]);
  else
    tr[x][msk][rmin] = max(tr[2 * x][msk][rmin], tr[2 * x + 1][msk][rmin]);
}
int qry(int x, int l, int r, int ql, int qr, int msk, bool rmin) {
  if (l > r || l > qr || r < ql) return rmin ? 1000000007 : -1000000007;
  if (l >= ql && r <= qr) return tr[x][msk][rmin];
  int m = (l + r) / 2;
  int q1 = qry(2 * x, l, m, ql, qr, msk, rmin);
  int q2 = qry(2 * x + 1, m + 1, r, ql, qr, msk, rmin);
  if (rmin) return min(q1, q2);
  return max(q1, q2);
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < (1 << k); i++) {
    bld(1, 1, n, i, 0);
    bld(1, 1, n, i, 1);
  }
  int q;
  cin >> q;
  while (q--) {
    int ty;
    cin >> ty;
    if (ty == 1) {
      int ind;
      cin >> ind;
      for (int i = 0; i < k; i++) {
        cin >> a[ind][i];
      }
      for (int i = 0; i < (1 << k); i++) {
        upd(1, 1, n, ind, i, 0);
        upd(1, 1, n, ind, i, 1);
      }
    } else {
      int l, r;
      cin >> l >> r;
      int ans = 0;
      for (int i = 0; i < (1 << k); i++) {
        ans = max(ans, qry(1, 1, n, l, r, i, 0) - qry(1, 1, n, l, r, i, 1));
      }
      cout << ans << endl;
    }
  }
  return 0;
}
