#include <bits/stdc++.h>
using namespace std;
mt19937 gen(time(0));
const int N = 2e5 + 500;
const long long mod = 1e9 + 7;
const long double eps = 0.0000000000001;
const long long inf = 1e9;
int n, k;
long long pr = 1;
vector<int> ma[32];
int a[N][5];
int z[33];
void upd(int i, int v, int zn) {
  ma[i][v] = zn;
  v /= 2;
  while (v) {
    ma[i][v] = max(ma[i][v * 2], ma[i][v * 2 + 1]);
    v /= 2;
  }
}
int maxx(int i, int l, int r, int v, int cl, int cr) {
  if (l > cr || r < cl) return -inf;
  if (l <= cl && cr <= r) return ma[i][v];
  int mid = (cl + cr) / 2;
  return max(maxx(i, l, r, v * 2, cl, mid),
             maxx(i, l, r, v * 2 + 1, mid + 1, cr));
}
void add(int i) {
  for (int mask = 0; mask < (1 << k); mask++) {
    int s = 0;
    for (int j = 0; j < k; j++) {
      bool bit = (mask & (1 << j));
      if (bit)
        s += a[i][j];
      else
        s -= a[i][j];
    }
    upd(mask, pr + i, s);
  }
}
int solve(int l, int r) {
  if (l == r) return 0;
  int ans = 0;
  for (int mask = 0; mask < (1 << k); mask++) {
    z[mask] = maxx(mask, pr + l, pr + r, 1, pr, pr + pr - 1);
  }
  int ch = (1 << k) - 1;
  for (int mask = 0; mask < (1 << k); mask++) {
    int ask = (mask ^ ch);
    ans = max(ans, z[mask] + z[ask]);
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  cin >> n >> k;
  while (pr < n) pr *= 2;
  for (int i = 0; i < 32; i++) {
    ma[i].resize(3 * pr);
    for (int j = 0; j < pr + pr; j++) {
      ma[i][j] = -inf;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      cin >> a[i][j];
    }
    add(i);
  }
  int q;
  cin >> q;
  for (int l = 0; l < q; l++) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      cin >> i;
      i--;
      for (int j = 0; j < k; j++) {
        cin >> a[i][j];
      }
      add(i);
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      cout << solve(l, r) << '\n';
    }
  }
}
