#include <bits/stdc++.h>
using namespace std;
struct nd {
  int pma[32];
  nd() {
    for (int i = 0; i < 32; i++) pma[i] = -(1 << 29);
  }
};
int n, k;
const int maxn = 200200;
nd t[maxn << 1];
nd merge(nd &a, nd &b) {
  nd ans;
  for (int i = 0; i < 1 << k; i++) ans.pma[i] = max(a.pma[i], b.pma[i]);
  return ans;
}
void modify(int p, int u[]) {
  nd x;
  for (int i = 0; i < 1 << k; i++) {
    int s = 0;
    for (int j = 0; j < k; j++) {
      if (i & (1 << j))
        s += u[j];
      else
        s -= u[j];
    }
    x.pma[i] = s;
  }
  for (t[p += n] = x; p > 1; p >>= 1) t[p >> 1] = merge(t[p], t[p ^ 1]);
}
nd query(int l, int r) {
  nd res;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = merge(res, t[l++]);
    if (r & 1) res = merge(res, t[--r]);
  }
  return res;
}
int v[10];
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) scanf("%d", v + j);
    modify(i, v);
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int ty;
    scanf("%d", &ty);
    if (ty == 2) {
      int l, r;
      scanf("%d %d", &l, &r);
      l--;
      nd p = query(l, r);
      int ans = -(1 << 30);
      int msk = (1 << k) - 1;
      for (int j = 0; j < 1 << k; j++)
        ans = max(ans, p.pma[j] + p.pma[j ^ msk]);
      printf("%d\n", ans);
    } else {
      int p;
      scanf("%d", &p);
      p--;
      for (int j = 0; j < k; j++) scanf("%d", v + j);
      modify(p, v);
    }
  }
  return 0;
}
