#include <bits/stdc++.h>
using namespace std;
int a[10], sg[35][800010][2];
vector<int> v;
void upd(int i, int id, int l, int r, int x, int val) {
  if (l == r) {
    sg[i][id][0] = val;
    sg[i][id][1] = val;
    return;
  }
  int lc = id << 1, rc = id << 1 | 1, m = (l + r) >> 1;
  if (x <= m)
    upd(i, lc, l, m, x, val);
  else
    upd(i, rc, m + 1, r, x, val);
  sg[i][id][0] = min(sg[i][lc][0], sg[i][rc][0]);
  sg[i][id][1] = max(sg[i][lc][1], sg[i][rc][1]);
  return;
}
pair<int, int> qry(int i, int id, int l, int r, int l1, int r1) {
  if (r1 < l || l1 > r || r < l) return make_pair(1e8, -1e8);
  if (l >= l1 && r <= r1) return make_pair(sg[i][id][0], sg[i][id][1]);
  int lc = id << 1, rc = id << 1 | 1, m = (l + r) >> 1;
  pair<int, int> p1, p2;
  p1 = qry(i, lc, l, m, l1, r1), p2 = qry(i, rc, m + 1, r, l1, r1);
  return make_pair(min(p1.first, p2.first), max(p1.second, p2.second));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, n, k, tp, l, m, q, r, mx;
  pair<int, int> pr;
  cin >> n >> k;
  for (i = 0; i < (1ll << k); i++)
    for (j = 0; j <= 4 * n; j++) sg[i][j][0] = 1e8, sg[i][j][1] = -1e8;
  for (i = 1; i <= n; i++) {
    for (j = 0; j < k; j++) cin >> a[j];
    for (l = 0; l < (1ll << k); l++) {
      tp = l;
      v.clear();
      while (tp > 0) {
        v.push_back(tp % 2);
        tp /= 2;
      }
      while ((int)(v.size()) < k) v.push_back(0);
      tp = 0;
      for (m = 0; m < k; m++)
        if (v[m] == 0)
          tp -= a[m];
        else
          tp += a[m];
      upd(l, 1, 1, n, i, tp);
    }
  }
  cin >> q;
  while (q--) {
    cin >> tp;
    if (tp == 1) {
      cin >> i;
      for (j = 0; j < k; j++) cin >> a[j];
      for (l = 0; l < (1ll << k); l++) {
        tp = l;
        v.clear();
        while (tp > 0) {
          v.push_back(tp % 2);
          tp /= 2;
        }
        while ((int)(v.size()) < k) v.push_back(0);
        tp = 0;
        for (m = 0; m < k; m++)
          if (v[m] == 0)
            tp -= a[m];
          else
            tp += a[m];
        upd(l, 1, 1, n, i, tp);
      }
    } else {
      cin >> l >> r;
      mx = 0;
      for (i = 0; i < (1ll << k); i++) {
        pr = qry(i, 1, 1, n, l, r);
        mx = max(mx, pr.second - pr.first);
      }
      cout << mx << "\n";
    }
  }
  return 0;
}
