#include <bits/stdc++.h>
using namespace std;
int N, K;
int B[5];
vector<int> A[1 << 5];
int Q;
int C, L, R;
pair<int, int> mix(pair<int, int> a, pair<int, int> b) {
  return {max(a.first, b.first), min(a.second, b.second)};
}
pair<int, int> Tree[1 << 5][4 * 200005];
void build(int b, int l = 0, int r = N - 1, int p = 0) {
  if (l == r) {
    Tree[b][p] = {A[b][l], A[b][l]};
    return;
  }
  int mid = (l + r) >> 1;
  build(b, l, mid, (p << 1) | 1);
  build(b, mid + 1, r, (p << 1) + 2);
  Tree[b][p] = mix(Tree[b][(p << 1) | 1], Tree[b][(p << 1) + 2]);
}
void update(int b, int i, int v, int l = 0, int r = N - 1, int p = 0) {
  if (l == r) {
    Tree[b][p] = {v, v};
    return;
  }
  int mid = (l + r) >> 1;
  if (i <= mid)
    update(b, i, v, l, mid, (p << 1) | 1);
  else
    update(b, i, v, mid + 1, r, (p << 1) + 2);
  Tree[b][p] = mix(Tree[b][(p << 1) | 1], Tree[b][(p << 1) + 2]);
}
pair<int, int> query(int b, int ql, int qr, int l = 0, int r = N - 1,
                     int p = 0) {
  if (qr < l || r < ql) return {-1e9, +1e9};
  if (ql <= l && r <= qr) return Tree[b][p];
  int mid = (l + r) >> 1;
  return mix(query(b, ql, qr, l, mid, (p << 1) | 1),
             query(b, ql, qr, mid + 1, r, (p << 1) + 2));
}
vector<int> poss(int *B) {
  vector<int> poss;
  for (int b = 0; b < (1 << K); b++) {
    int op = 0;
    for (int j = 0; j < K; j++) op += (b & (1 << j) ? +1 : -1) * B[j];
    poss.push_back(op);
  }
  return poss;
}
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < K; j++) scanf("%d", &B[j]);
    int l = 0;
    for (int j : poss(B)) A[l++].push_back(j);
  }
  for (int i = 0; i < (1 << K); i++) build(i);
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &C, &L);
    if (C == 1) {
      for (int i = 0; i < K; i++) scanf("%d", &B[i]);
      int l = 0;
      for (int j : poss(B)) update(l++, L - 1, j);
    } else {
      scanf("%d", &R);
      int ans = 0;
      for (int i = 0; i < (1 << K); i++) {
        auto q = query(i, L - 1, R - 1);
        ans = max(ans, q.first - q.second);
      }
      printf("%d\n", ans);
    }
  }
}
