#include <bits/stdc++.h>
using namespace std;
void Read(int &val) {
  val = 0;
  char c;
  do {
    c = getchar();
  } while (!isdigit(c) && c != '-');
  bool Minus = false;
  if (c == '-') {
    Minus = true;
    c = getchar();
  }
  while (isdigit(c)) {
    val = val * 10 + c - '0';
    c = getchar();
  }
  if (Minus) val = -val;
}
void Write(int val) {
  if (val < 0)
    putchar('-'), Write(-val);
  else if (val < 10)
    putchar('0' + val);
  else
    Write(val / 10), putchar('0' + val % 10);
}
const int N = 2e5 + 4, MASK = 40, oo = 1e9 + 7;
int n, k, val[10];
struct Interval_Tree {
  int minNode[4 * N], maxNode[4 * N];
  void update(int i, int l, int r, int x, int y, int val) {
    if (l > y || x > r) return;
    if (x <= l && r <= y) {
      minNode[i] = maxNode[i] = val;
      return;
    }
    int mid = (l + r) / 2;
    update(2 * i, l, mid, x, y, val);
    update(2 * i + 1, mid + 1, r, x, y, val);
    minNode[i] = min(minNode[2 * i], minNode[2 * i + 1]);
    maxNode[i] = max(maxNode[2 * i], maxNode[2 * i + 1]);
  }
  int getMax(int i, int l, int r, int x, int y) {
    if (l > y || x > r) return -oo;
    if (x <= l && r <= y) return maxNode[i];
    int mid = (l + r) / 2;
    int tmp1 = getMax(2 * i, l, mid, x, y),
        tmp2 = getMax(2 * i + 1, mid + 1, r, x, y);
    return max(tmp1, tmp2);
  }
  int getMin(int i, int l, int r, int x, int y) {
    if (l > y || x > r) return oo;
    if (x <= l && r <= y) return minNode[i];
    int mid = (l + r) / 2;
    int tmp1 = getMin(2 * i, l, mid, x, y),
        tmp2 = getMin(2 * i + 1, mid + 1, r, x, y);
    return min(tmp1, tmp2);
  }
} IT[MASK];
bool BIT(int n, int k) { return n & (1 << k); }
void sol() {
  int Q, l, r, pos, type;
  Read(Q);
  while (Q--) {
    Read(type);
    if (type == 1) {
      Read(pos);
      for (int bit = 0; bit < k; ++bit) Read(val[bit]);
      for (int mask = 0; mask < (1 << k); ++mask) {
        int foo = 0;
        for (int bit = 0; bit < k; ++bit) {
          if (BIT(mask, bit))
            foo += val[bit];
          else
            foo -= val[bit];
        }
        IT[mask].update(1, 1, n, pos, pos, foo);
      }
    } else {
      Read(l);
      Read(r);
      int res = 0;
      for (int mask = 0; mask < (1 << k); ++mask) {
        int maxVal = IT[mask].getMax(1, 1, n, l, r);
        int minVal = IT[mask].getMin(1, 1, n, l, r);
        res = max(res, maxVal - minVal);
      }
      Write(res);
      putchar('\n');
    }
  }
}
int main() {
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
  }
  Read(n);
  Read(k);
  for (int i = 1; i <= n; ++i) {
    for (int bit = 0; bit < k; ++bit) Read(val[bit]);
    for (int mask = 0; mask < (1 << k); ++mask) {
      int foo = 0;
      for (int bit = 0; bit < k; ++bit) {
        if (BIT(mask, bit))
          foo += val[bit];
        else
          foo -= val[bit];
      }
      IT[mask].update(1, 1, n, i, i, foo);
    }
  }
  sol();
  return 0;
}
