#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
int pow(int a, int b) {
  int prod = 1;
  int mult = a;
  while (b != 0) {
    if (b % 2) {
      prod *= mult;
      prod %= mod2;
    }
    mult *= mult;
    mult %= mod2;
    b /= 2;
  }
  return prod;
}
int mod_inv(int q, int mod) { return pow(q, mod - 2); }
pair<int, int> combine(pair<int, int> a, pair<int, int> b) {
  pair<int, int> out;
  out.first = max(a.first, b.first);
  out.second = min(a.second, b.second);
  return out;
}
const int MAXN = 2e5 + 10;
pair<int, int> seg_Tree[32][4 * MAXN];
void update(int tree, int node, int tl, int tr, int val, int pos) {
  if (tl == tr) {
    seg_Tree[tree][node] = {val, val};
    return;
  }
  int tm = (tl + tr) / 2;
  if (tm >= pos)
    update(tree, 2 * node, tl, tm, val, pos);
  else
    update(tree, 2 * node + 1, tm + 1, tr, val, pos);
  seg_Tree[tree][node] =
      combine(seg_Tree[tree][2 * node], seg_Tree[tree][2 * node + 1]);
}
pair<int, int> query(int tree, int node, int tl, int tr, int l, int r) {
  if (l > r) return {-INF, INF};
  if (l == tl && r == tr) return seg_Tree[tree][node];
  int tm = (tl + tr) / 2;
  return combine(query(tree, 2 * node, tl, tm, l, min(r, tm)),
                 query(tree, 2 * node + 1, tm + 1, tr, max(l, tm + 1), r));
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    vector<int> a(k);
    for (int j = 0; j < k; j++) cin >> a[j];
    for (int j = 0; j < (1 << k); j++) {
      int sum = 0;
      for (int l = 0; l < k; l++) {
        if ((j & (1 << l)) == 0)
          sum -= a[l];
        else
          sum += a[l];
      }
      update(j, 1, 1, n, sum, i);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int i;
      vector<int> a(k);
      cin >> i;
      for (auto &ia : a) cin >> ia;
      for (int j = 0; j < (1 << k); j++) {
        int sum = 0;
        for (int l = 0; l < k; l++) {
          if ((j & (1 << l)) == 0)
            sum -= a[l];
          else
            sum += a[l];
        }
        update(j, 1, 1, n, sum, i);
      }
    } else {
      int l, r;
      cin >> l >> r;
      int best = 0;
      for (int i = 0; i < (1 << k); i++) {
        auto qu = query(i, 1, 1, n, l, r);
        best = max(best, qu.first - qu.second);
      }
      cout << best << '\n';
    }
  }
}
