#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n, k;
class Aint {
  pair<int, int> t[4 * N];
  pair<int, int> ans;
  int l, r, val;
  void dfs(int nod = 1, int st = 1, int dr = n) {
    if (l <= st && dr <= r) {
      t[nod] = {val, val};
      return;
    }
    int mij((st + dr) >> 1);
    nod <<= 1;
    if (l <= mij) dfs(nod, st, mij);
    if (r > mij) dfs(nod + 1, mij + 1, dr);
    t[nod >> 1] = {min(t[nod].first, t[nod + 1].first),
                   max(t[nod].second, t[nod + 1].second)};
  }
  void run(int nod = 1, int st = 1, int dr = n) {
    if (l <= st && dr <= r) {
      ans = {min(ans.first, t[nod].first), max(ans.second, t[nod].second)};
      return;
    }
    int mij((st + dr) >> 1);
    nod <<= 1;
    if (l <= mij) run(nod, st, mij);
    if (r > mij) run(nod + 1, mij + 1, dr);
  }

 public:
  Aint() {
    for (int i = 0; i < 4 * N; ++i) t[i] = {1e7, -1e7};
  }
  void update(int aval, int poz) {
    val = aval;
    l = r = poz;
    dfs();
  }
  int query(int ast, int adr) {
    l = ast;
    r = adr;
    ans = {1e7, -1e7};
    run();
    return ans.second - ans.first;
  }
} aint[35];
int pzu;
int v[6];
void bkt(int p = 0, int x = 0, int val = 0) {
  if (p == k) {
    aint[x].update(val, pzu);
    return;
  }
  bkt(p + 1, x, val - v[p]);
  bkt(p + 1, (x ^ (1 << p)), val + v[p]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int q, t, l, r;
  cin >> n >> k;
  for (pzu = 1; pzu <= n; ++pzu) {
    for (int j = 0; j < k; ++j) cin >> v[j];
    bkt();
  }
  cin >> q;
  while (q--) {
    cin >> t;
    if (t - 1) {
      cin >> l >> r;
      int ans(0);
      for (int i = 0; i < (1 << k); ++i) ans = max(ans, aint[i].query(l, r));
      cout << ans << '\n';
    } else {
      cin >> pzu;
      for (int i = 0; i < k; ++i) cin >> v[i];
      bkt();
    }
  }
  return 0;
}
