#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int M = 32;
const int inf = 1 << 30;
int n, qn, k, a[N][6], res[M];
inline int max(int x, int y) { return x > y ? x : y; }
inline void chkMax(int &x, int y) {
  if (y > x) x = y;
}
inline void read(int &X) {
  X = 0;
  char ch = 0;
  int op = 1;
  for (; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-') op = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    X = (X << 3) + (X << 1) + ch - 48;
  X *= op;
}
namespace SegT {
int s[N << 2][M];
inline void up(int p, int y) { s[p][y] = max(s[p << 1][y], s[p << 1 | 1][y]); }
void modify(int p, int l, int r, int x, int y, int v) {
  if (l == r) {
    s[p][y] = v;
    return;
  }
  if (x <= ((l + r) >> 1))
    modify(p << 1, l, ((l + r) >> 1), x, y, v);
  else
    modify(p << 1 | 1, ((l + r) >> 1) + 1, r, x, y, v);
  up(p, y);
}
void query(int p, int l, int r, int x, int y) {
  if (x <= l && y >= r) {
    for (int i = 0; i < (1 << k); i++) chkMax(res[i], s[p][i]);
    return;
  }
  if (x <= ((l + r) >> 1)) query(p << 1, l, ((l + r) >> 1), x, y);
  if (y > ((l + r) >> 1)) query(p << 1 | 1, ((l + r) >> 1) + 1, r, x, y);
}
}  // namespace SegT
using namespace SegT;
int main() {
  read(n), read(k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) read(a[i][j]);
    for (int j = 0; j < (1 << k); j++) {
      int sum = 0;
      for (int p = 1; p <= k; p++)
        if ((j >> (p - 1)) & 1)
          sum += a[i][p];
        else
          sum -= a[i][p];
      modify(1, 1, n, i, j, sum);
    }
  }
  read(qn);
  for (int op; qn--;) {
    read(op);
    if (op == 1) {
      int x;
      read(x);
      for (int i = 1; i <= k; i++) read(a[x][i]);
      for (int i = 0; i < (1 << k); i++) {
        int sum = 0;
        for (int j = 1; j <= k; j++)
          if ((i >> (j - 1)) & 1)
            sum += a[x][j];
          else
            sum -= a[x][j];
        modify(1, 1, n, x, i, sum);
      }
    } else {
      int x, y;
      read(x), read(y);
      for (int i = 0; i < (1 << k); i++) res[i] = -inf;
      query(1, 1, n, x, y);
      int ans = -inf;
      for (int i = 0; i < (1 << k); i++)
        chkMax(ans, res[i] + res[((1 << k) - 1) ^ i]);
      printf("%d\n", ans);
    }
  }
  return 0;
}
