#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100;
inline void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int Lim, k;
struct Segment_Node {
  int lson, rson;
  int Mx[32];
  Segment_Node() {
    lson = rson = 0;
    memset(Mx, 0, sizeof(Mx));
  }
  friend Segment_Node operator+(Segment_Node A, Segment_Node B) {
    Segment_Node ret;
    ret.lson = A.lson;
    ret.rson = B.rson;
    for (int i = 0; i <= Lim; ++i) {
      ret.Mx[i] = max(A.Mx[i], B.Mx[i]);
    }
    return ret;
  }
  void set(int *A, int k) {
    for (int i = 0; i <= Lim; ++i) Mx[i] = 0;
    for (int i = 0; i <= Lim; ++i) {
      int tmp = 0;
      for (int j = 0; j < k; ++j) {
        if (i & (1 << j)) {
          tmp += A[j];
        } else
          tmp -= A[j];
      }
      Mx[i] = tmp;
    }
  }
} T[N << 2];
int a[N][5];
void Build(int p, int l, int r) {
  T[p].lson = l;
  T[p].rson = r;
  if (l == r) {
    T[p].set(a[l], k);
    return;
  }
  int mid = (l + r) >> 1;
  Build((p << 1), l, mid);
  Build((p << 1 | 1), mid + 1, r);
  T[p] = T[(p << 1)] + T[(p << 1 | 1)];
}
void Update(int p, int pos) {
  if (T[p].lson == T[p].rson) {
    T[p].set(a[T[p].lson], k);
    return;
  }
  int mid = (T[p].lson + T[p].rson) >> 1;
  if (pos <= mid)
    Update((p << 1), pos);
  else
    Update((p << 1 | 1), pos);
  T[p] = T[(p << 1)] + T[(p << 1 | 1)];
}
Segment_Node Query(int p, int l, int r) {
  if (l <= T[p].lson && T[p].rson <= r) {
    return T[p];
  }
  int mid = (T[p].lson + T[p].rson) >> 1;
  if (l <= mid && mid >= r) return Query((p << 1), l, r);
  if (mid < r && l > mid) return Query((p << 1 | 1), l, r);
  if (l <= mid && mid < r)
    return Query((p << 1), l, r) + Query((p << 1 | 1), l, r);
}
int n;
void Get() {
  int l, r;
  read(l);
  read(r);
  Segment_Node now = Query(1, l, r);
  int ans = 0;
  for (int i = 0; i <= Lim; ++i) {
    ans = max(ans, now.Mx[i] + now.Mx[Lim ^ i]);
  }
  cout << ans << '\n';
}
int main() {
  read(n);
  read(k);
  Lim = (1 << k) - 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      read(a[i][j]);
    }
  }
  Build(1, 1, n);
  int Q;
  read(Q);
  while (Q--) {
    int opt;
    read(opt);
    if (opt == 2) {
      Get();
    } else {
      int pos;
      read(pos);
      for (int i = 0; i < k; ++i) {
        read(a[pos][i]);
      }
      Update(1, pos);
    }
  }
  return 0;
}
