#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
vector<int> dr[800000];
vector<int> dr2[800000];
int k, kk;
vector<int> a[800000];
vector<int> iz;
int f(int c, vector<int> aa) {
  int c2 = c, ans = 0;
  for (int j = 0; j < k; j++) {
    if (c2 % 2 == 0) {
      ans += aa[j];
    } else {
      ans -= aa[j];
    }
    c2 /= 2;
  }
  return ans;
}
void bl(int v, int l, int r) {
  if (r - l == 1) {
    for (int i = 0; i < kk; i++) {
      dr[v].resize(kk);
      dr2[v].resize(kk);
      dr[v][i] = f(i, a[l]);
      dr2[v][i] = f(i, a[l]);
    }
    return;
  }
  bl(2 * v + 1, l, (l + r) / 2);
  bl(2 * v + 2, (l + r) / 2, r);
  dr[v].resize(kk);
  dr2[v].resize(kk);
  for (int i = 0; i < kk; i++) {
    dr[v][i] = max(dr[2 * v + 1][i], dr[2 * v + 2][i]);
    dr2[v][i] = min(dr2[2 * v + 1][i], dr2[2 * v + 2][i]);
  }
}
vector<int> mx(int v, int l, int r, int ln, int rn) {
  if (r <= ln || rn <= l) {
    vector<int> ttt(kk);
    for (int i = 0; i < kk; i++) {
      ttt[i] = -MOD;
    }
    return ttt;
  }
  if (ln <= l && r <= rn) {
    return dr[v];
  }
  vector<int> a1 = mx(2 * v + 1, l, (l + r) / 2, ln, rn);
  vector<int> a2 = mx(2 * v + 2, (l + r) / 2, r, ln, rn);
  vector<int> a3(kk);
  for (int i = 0; i < kk; i++) {
    a3[i] = max(a1[i], a2[i]);
  }
  return a3;
}
vector<int> mn(int v, int l, int r, int ln, int rn) {
  if (r <= ln || rn <= l) {
    vector<int> ttt(kk);
    for (int i = 0; i < kk; i++) {
      ttt[i] = MOD;
    }
    return ttt;
  }
  if (ln <= l && r <= rn) {
    return dr2[v];
  }
  vector<int> a1 = mn(2 * v + 1, l, (l + r) / 2, ln, rn);
  vector<int> a2 = mn(2 * v + 2, (l + r) / 2, r, ln, rn);
  vector<int> a3(kk);
  for (int i = 0; i < kk; i++) {
    a3[i] = min(a1[i], a2[i]);
  }
  return a3;
}
void gt(int v, int l, int r, int id) {
  if (id < l || id >= r) {
    return;
  }
  if (l == r - 1) {
    dr[v] = iz;
    dr2[v] = iz;
    return;
  }
  gt(2 * v + 1, l, (l + r) / 2, id);
  gt(2 * v + 2, (l + r) / 2, r, id);
  dr[v].resize(kk);
  dr2[v].resize(kk);
  for (int i = 0; i < kk; i++) {
    dr[v][i] = max(dr[2 * v + 1][i], dr[2 * v + 2][i]);
    dr2[v][i] = min(dr2[2 * v + 1][i], dr2[2 * v + 2][i]);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n >> k;
  kk = (int)(pow(2, k));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      int r;
      cin >> r;
      a[i].push_back(r);
    }
  }
  bl(0, 0, n);
  int q;
  cin >> q;
  while (q--) {
    int c;
    cin >> c;
    if (c == 1) {
      int idd;
      cin >> idd;
      idd--;
      iz.resize(kk);
      vector<int> izz(k);
      for (int j = 0; j < k; j++) {
        cin >> izz[j];
        a[idd][j] = izz[j];
      }
      for (int j = 0; j < kk; j++) {
        iz[j] = f(j, a[idd]);
      }
      gt(0, 0, n, idd);
    } else {
      int L, R;
      cin >> L >> R;
      int mxx = -MOD;
      vector<int> mem = mx(0, 0, n, L - 1, R);
      vector<int> mem2 = mn(0, 0, n, L - 1, R);
      for (int i = 0; i < kk; i++) {
        mxx = max(mxx, mem[i] - mem2[i]);
      }
      cout << mxx << endl;
    }
  }
}
