#include <bits/stdc++.h>
template <class t>
void maxi(t &x, t y) {
  if (x < y) x = y;
}
template <class t>
void mini(t &x, t y) {
  if (x > y) x = y;
}
using namespace std;
pair<int, int> sg[1 << 5][4 * 200005];
int a[200005][6], n, k;
int apply(int a[], int bit) {
  int v = 0;
  for (int(i) = 0; (i) < (k); (i)++) {
    if ((bit >> i) & 1)
      v -= a[i];
    else
      v += a[i];
  }
  return v;
}
void seg_build(int bit, int l = 1, int r = n + 1, int st = 1) {
  int v = apply(a[l], bit);
  if (r - l < 2) {
    sg[bit][st] = make_pair(v, v);
    return;
  }
  int mid = (l + r) >> 1;
  st <<= 1;
  seg_build(bit, l, mid, st);
  seg_build(bit, mid, r, st + 1);
  pair<int, int> x = sg[bit][st], y = sg[bit][st + 1];
  sg[bit][st >> 1] = make_pair(min(x.first, y.first), max(x.second, y.second));
}
pair<int, int> seg_query(int bit, int a, int b, int l = 1, int r = n + 1,
                         int st = 1) {
  if (l == a && r == b + 1) {
    return sg[bit][st];
  }
  int mid = (l + r) >> 1;
  st <<= 1;
  pair<int, int> ans = make_pair(INT_MAX, INT_MIN);
  if (b < mid) return seg_query(bit, a, b, l, mid, st);
  if (a >= mid) return seg_query(bit, a, b, mid, r, st + 1);
  pair<int, int> x = seg_query(bit, a, mid - 1, l, mid, st);
  pair<int, int> y = seg_query(bit, mid, b, mid, r, st + 1);
  return make_pair(min(x.first, y.first), max(x.second, y.second));
}
void seg_update(int bit, int in, int l = 1, int r = n + 1, int st = 1) {
  if (r - l < 2) {
    int v = apply(a[in], bit);
    sg[bit][st] = make_pair(v, v);
    return;
  }
  int mid = (l + r) >> 1;
  st <<= 1;
  if (in < mid) {
    seg_update(bit, in, l, mid, st);
  } else
    seg_update(bit, in, mid, r, st + 1);
  pair<int, int> x = sg[bit][st], y = sg[bit][st + 1];
  sg[bit][st >> 1] = make_pair(min(x.first, y.first), max(x.second, y.second));
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int(i) = 1; (i) <= (n); (i)++) {
    for (int(j) = 0; (j) < (k); (j)++) cin >> a[i][j];
  }
  for (int(i) = 0; (i) < (1 << k); (i)++) seg_build(i);
  int q;
  cin >> (q);
  ;
  while (q--) {
    int t;
    cin >> (t);
    ;
    if (t == 1) {
      int i;
      cin >> (i);
      ;
      for (int(j) = 0; (j) < (k); (j)++) cin >> a[i][j];
      for (int(j) = 0; (j) < (1 << k); (j)++) seg_update(j, i);
    } else {
      int l, r;
      cin >> (l) >> (r);
      ;
      int ans = INT_MIN;
      for (int(i) = 0; (i) < (1 << k); (i)++) {
        auto [mi, ma] = seg_query(i, l, r);
        maxi(ans, ma - mi);
      }
      cout << ans << endl;
    }
  }
  return 0;
}
