#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
vector<int> A[N];
struct Node {
  vector<int> p;
  Node(vector<int> v) {
    for (int i = 0; i < 16; i++) {
      int sum = 0;
      for (int j = 0; j < 5; j++) {
        if (i & (1 << j))
          sum += v[j];
        else
          sum -= v[j];
      }
      p.push_back(sum);
    }
  }
  Node() { p.resize(16, 0); }
};
pair<Node, Node> tree[4 * N];
inline void combine(pair<Node, Node> &a, pair<Node, Node> &b,
                    pair<Node, Node> &c) {
  for (__typeof(((int)a.first.p.size() - 1)) i = (0);
       i <= ((int)a.first.p.size() - 1); i++) {
    a.first.p[i] = max(b.first.p[i], c.first.p[i]);
    a.second.p[i] = min(b.second.p[i], c.second.p[i]);
  }
}
inline void update(int node, int st, int et, int idx, vector<int> &val) {
  if (st == et) {
    tree[node] = make_pair(Node(val), Node(val));
    return;
  }
  int mid = (st + et) / 2;
  if (idx <= mid)
    update(node * 2, st, mid, idx, val);
  else
    update(node * 2 + 1, mid + 1, et, idx, val);
  combine(tree[node], tree[2 * node], tree[2 * node + 1]);
}
inline pair<Node, Node> query(int node, int st, int et, int l, int r) {
  if (l > et or r < st) {
    pair<Node, Node> pp;
    for (int i = 0; i < 16; i++) {
      pp.first.p[i] = -10000000;
      pp.second.p[i] = 10000000;
    }
    return pp;
  }
  if (st >= l and et <= r)
    return tree[node];
  else {
    int mid = (st + et) / 2;
    pair<Node, Node> p1, p2, res;
    p1 = query(2 * node, st, mid, l, r);
    p2 = query(2 * node + 1, mid + 1, et, l, r);
    combine(res, p1, p2);
    return res;
  }
}
void solve() {
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  for (__typeof((n)) i = (1); i <= (n); i++) {
    vector<int> v;
    for (int j = 0; j < 5; j++) {
      int x;
      if (j < k)
        scanf("%d", &x);
      else
        x = 0;
      v.push_back(x);
    }
    A[i] = v;
    update(1, 1, n, i, A[i]);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int i;
      scanf("%d", &i);
      vector<int> v;
      for (int i = 0; i < 5; i++) {
        int x;
        if (i < k)
          scanf("%d", &x);
        else
          x = 0;
        v.push_back(x);
      }
      A[i] = v;
      update(1, 1, n, i, A[i]);
    } else {
      int l, r;
      scanf("%d", &l);
      scanf("%d", &r);
      pair<Node, Node> p = query(1, 1, n, l, r);
      int ans = 0;
      for (int i = 0; i < 16; i++) {
        ans = max(ans, p.first.p[i] - p.second.p[i]);
      }
      printf("%d\n", ans);
    }
  }
}
signed main() {
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
