#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int maxn = 262144;
const int maxk = 6;
const int inf = 1e9 + 5;
struct seg_treemax {
  int t[maxn * 2 + 20];
  void update(int v, int tl, int tr, int p, int x) {
    if (tl == tr) {
      t[v] = x;
      return;
    }
    int tm = (tl + tr) >> 1;
    if (p <= tm) {
      update(v << 1, tl, tm, p, x);
    } else {
      update(v << 1 | 1, tm + 1, tr, p, x);
    }
    t[v] = max(t[v << 1], t[v << 1 | 1]);
  }
  int query(int v, int tl, int tr, int l, int r) {
    if (tl > r || tr < l) {
      return -inf;
    }
    if (tl >= l && tr <= r) {
      return t[v];
    }
    int tm = (tl + tr) >> 1;
    return max(query(v << 1, tl, tm, l, r),
               query(v << 1 | 1, tm + 1, tr, l, r));
  }
};
struct seg_treemin {
  int t[maxn * 2 + 20];
  void update(int v, int tl, int tr, int p, int x) {
    if (tl == tr) {
      t[v] = x;
      return;
    }
    int tm = (tl + tr) >> 1;
    if (p <= tm) {
      update(v << 1, tl, tm, p, x);
    } else {
      update(v << 1 | 1, tm + 1, tr, p, x);
    }
    t[v] = min(t[v << 1], t[v << 1 | 1]);
    return;
  }
  int query(int v, int tl, int tr, int l, int r) {
    if (tl > r || tr < l) {
      return inf;
    }
    if (tl >= l && tr <= r) {
      return t[v];
    }
    int tm = (tl + tr) >> 1;
    return min(query(v << 1, tl, tm, l, r),
               query(v << 1 | 1, tm + 1, tr, l, r));
  }
};
seg_treemax tmax[1 << maxk];
seg_treemin tmin[1 << maxk];
vector<int> a[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  scanf("%d %d", &n, &k);
  int st = 1 << k;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < k; ++j) {
      int x;
      scanf("%d", &x);
      a[i].push_back(x);
    }
  for (int i = 0; i < st; i++) {
    for (int j = 0; j < n; j++) {
      int sum = 0;
      for (int v = 0; v < k; v++) {
        int val = a[j][v];
        if ((i & (1 << v)) > 0) val *= -1;
        sum += val;
      }
      tmax[i].t[j + maxn] = sum;
      tmin[i].t[j + maxn] = sum;
    }
  }
  for (int i = 0; i < st; ++i)
    for (int j = maxn - 1; j > 0; --j) {
      tmax[i].t[j] = max(tmax[i].t[j << 1], tmax[i].t[j << 1 | 1]);
      tmin[i].t[j] = min(tmin[i].t[j << 1], tmin[i].t[j << 1 | 1]);
    }
  int q;
  scanf("%d", &q);
  for (int ii = 0; ii < q; ++ii) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int v;
      scanf("%d", &v);
      v--;
      for (int i = 0; i < k; ++i) scanf("%d", &a[v][i]);
      for (int i = 0; i < st; ++i) {
        int sum = 0;
        for (int j = 0; j < k; j++) {
          int val = a[v][j];
          if ((i & (1 << j)) > 0) val *= -1;
          sum += val;
        }
        tmax[i].update(1, 0, maxn - 1, v, sum);
        tmin[i].update(1, 0, maxn - 1, v, sum);
      }
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      l--;
      r--;
      int ans = -1;
      for (int i = 0; i < st; ++i) {
        int mx = tmax[i].query(1, 0, maxn - 1, l, r);
        int mn = tmin[i].query(1, 0, maxn - 1, l, r);
        ans = max(ans, mx - mn);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
