#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a < b) gcd(b, a);
  int r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
const int maxn = 1 << 24;
int n2, dat[32][600005][2];
int n, k;
int kazu;
void init(int n_) {
  for (int z = 0; z < kazu; z++) {
    n2 = 1;
    while (n2 < n_) n2 *= 2;
    for (int i = 0; i < 2 * n2 - 1; i++) {
      dat[z][i][0] = INT_MIN;
      dat[z][i][1] = INT_MAX;
    }
  }
}
void update(int kkkkk, int* a) {
  for (int z = 0; z < kazu; z++) {
    int kk = kkkkk + n2 - 1;
    int num = 0;
    for (int tmp = 0; tmp < k; tmp++) {
      if ((z >> tmp) & 1)
        num += a[tmp];
      else
        num -= a[tmp];
    }
    dat[z][kk][0] = num;
    dat[z][kk][1] = num;
    while (kk > 0) {
      kk = (kk - 1) / 2;
      dat[z][kk][0] = max(dat[z][kk * 2 + 1][0], dat[z][kk * 2 + 2][0]);
      dat[z][kk][1] = min(dat[z][kk * 2 + 1][1], dat[z][kk * 2 + 2][1]);
    }
  }
}
int query2(int z, int a, int b, int kkkkk, int l, int r) {
  if (r <= a || b <= l) return INT_MIN;
  if (a <= l && r <= b) return dat[z][kkkkk][0];
  return max(query2(z, a, b, kkkkk * 2 + 1, l, (l + r) / 2),
             query2(z, a, b, kkkkk * 2 + 2, (l + r) / 2, r));
}
int query3(int z, int a, int b, int kkkkk, int l, int r) {
  if (r <= a || b <= l) return INT_MAX;
  if (a <= l && r <= b) return dat[z][kkkkk][1];
  return min(query3(z, a, b, kkkkk * 2 + 1, l, (l + r) / 2),
             query3(z, a, b, kkkkk * 2 + 2, (l + r) / 2, r));
}
int query(int a, int b) {
  int ans = INT_MIN;
  for (int z = 0; z < kazu; z++) {
    ans = max(ans, query2(z, a, b, 0, 0, n2) - query3(z, a, b, 0, 0, n2));
  }
  return ans;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  kazu = 1 << k;
  kazu /= 2;
  init(n);
  int a[5];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      cin >> a[j];
    }
    update(i, a);
  }
  int q;
  cin >> q;
  int b[5];
  int inst;
  int l, r;
  for (int i = 0; i < q; i++) {
    cin >> inst;
    if (inst == 1) {
      cin >> l;
      for (int j = 0; j < k; j++) {
        cin >> b[j];
      }
      update(l - 1, b);
    } else {
      cin >> l >> r;
      cout << query(l - 1, r) << "\n";
    }
  }
}
