#include <bits/stdc++.h>
using namespace std;
const int kn = 2e5 + 5, N = 1e5 + 5;
const long long mod = 1e9 + 7, mod2 = 1e9 + 9;
const long long base = 31, base1 = 37;
int n, k, q;
int coor[kn][6];
int ITmax[4 * kn][32], ITmin[4 * kn][32];
void upd(int num, int id, int l, int r, int pos, int val) {
  if (l > pos || r < pos) return;
  if (l == r) {
    ITmax[id][num] = ITmin[id][num] = val;
    return;
  }
  int mid = (l + r) >> 1;
  upd(num, id << 1, l, mid, pos, val);
  upd(num, (id << 1) | 1, mid + 1, r, pos, val);
  ITmax[id][num] = max(ITmax[id << 1][num], ITmax[(id << 1) | 1][num]);
  ITmin[id][num] = min(ITmin[id << 1][num], ITmin[(id << 1) | 1][num]);
}
int getmax(int num, int id, int l, int r, int L, int R) {
  if (r < L || l > R) return -1e8;
  if (l >= L && r <= R) return ITmax[id][num];
  int mid = (l + r) >> 1;
  return max(getmax(num, id << 1, l, mid, L, R),
             getmax(num, (id << 1) | 1, mid + 1, r, L, R));
}
int getmin(int num, int id, int l, int r, int L, int R) {
  if (r < L || l > R) return 1e9;
  if (l >= L && r <= R) return ITmin[id][num];
  int mid = (l + r) >> 1;
  return min(getmin(num, id << 1, l, mid, L, R),
             getmin(num, (id << 1) | 1, mid + 1, r, L, R));
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      scanf("%d", &coor[i][j]);
    }
  }
  for (int j = 0; j < (1 << k); j++)
    for (int i = 1; i <= 4 * n; i++) ITmin[i][j] = 1e9, ITmax[i][j] = -1e8;
  for (int i = 0; i < (1 << k); i++) {
    for (int j = 1; j <= n; j++) {
      long long cur = 0;
      for (int tmp = 1; tmp <= k; tmp++) {
        cur += ((i >> (tmp - 1)) & 1) ? coor[j][tmp] : (-coor[j][tmp]);
      }
      upd(i, 1, 1, n, j, cur);
    }
  }
  scanf("%d", &q);
  while (q--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int id;
      scanf("%d", &id);
      for (int i = 1; i <= k; i++) scanf("%d", &coor[id][i]);
      for (int i = 0; i < (1 << k); i++) {
        int cur = 0;
        for (int tmp = 1; tmp <= k; tmp++)
          cur += ((i >> (tmp - 1)) & 1) ? coor[id][tmp] : (-coor[id][tmp]);
        upd(i, 1, 1, n, id, cur);
      }
    } else {
      int l, r, ans = 0;
      scanf("%d %d", &l, &r);
      for (int i = 0; i < (1 << k); i++)
        ans = max(ans, getmax(i, 1, 1, n, l, r) - getmin(i, 1, 1, n, l, r));
      printf("%d\n", ans);
    }
  }
}
