#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int n, K, q, pos[200005][7];
struct sta {
  int p[32];
};
sta operator+(sta a, sta b) {
  sta res;
  for (int i = 0; i < (1 << K); i++) res.p[i] = max(a.p[i], b.p[i]);
  return res;
}
struct Segment_Tree {
  sta v[200005 << 2];
  void build(int l, int r, int k) {
    if (l == r) {
      for (int i = 0; i < (1 << K); i++) {
        for (int j = 1; j <= K; j++) {
          if ((1 << (j - 1)) & i)
            v[k].p[i] += pos[l][j];
          else
            v[k].p[i] -= pos[l][j];
        }
      }
      return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, k << 1);
    build(mid + 1, r, k << 1 | 1);
    v[k] = v[k << 1] + v[k << 1 | 1];
  }
  void modify(int l, int r, int k, int x) {
    if (l == r) {
      for (int i = 0; i < (1 << K); i++) {
        v[k].p[i] = 0;
        for (int j = 1; j <= K; j++) {
          if ((1 << (j - 1)) & i)
            v[k].p[i] += pos[l][j];
          else
            v[k].p[i] -= pos[l][j];
        }
      }
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid)
      modify(l, mid, k << 1, x);
    else
      modify(mid + 1, r, k << 1 | 1, x);
    v[k] = v[k << 1] + v[k << 1 | 1];
  }
  sta query(int l, int r, int k, int x, int y) {
    if (l >= x && r <= y) return v[k];
    int mid = (l + r) >> 1;
    if (x > mid) return query(mid + 1, r, k << 1 | 1, x, y);
    if (y <= mid) return query(l, mid, k << 1, x, y);
    return query(l, mid, k << 1, x, y) + query(mid + 1, r, k << 1 | 1, x, y);
  }
} T;
int main() {
  n = read();
  K = read();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= K; j++) {
      pos[i][j] = read();
    }
  }
  T.build(1, n, 1);
  q = read();
  while (q--) {
    int opt = read();
    if (opt == 1) {
      int i = read();
      for (int j = 1; j <= K; j++) pos[i][j] = read();
      T.modify(1, n, 1, i);
    } else {
      int l = read(), r = read();
      sta res = T.query(1, n, 1, l, r);
      int ans = 0;
      for (int i = 0; i < (1 << K); i++)
        ans = max(ans, res.p[i] + res.p[(1 << K) - i - 1]);
      printf("%d\n", ans);
    }
  }
}
