#include <bits/stdc++.h>
using namespace std;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
class SegmentTree {
  int n;
  vector<T> data;

 public:
  T merge(T a, T b) { return min(a, b); }
  SegmentTree(int s) : n(1 << s), data(n * 2, numeric_limits<T>::max()) {}
  void update(int p, T val) {
    data[p += n] = val;
    while (p /= 2) {
      data[p] = merge(data[p * 2], data[p * 2 + 1]);
    }
  }
  T query(int l, int r) {
    l += n;
    r += n;
    T res1 = numeric_limits<T>::max(), res2 = numeric_limits<T>::max();
    while (l != r) {
      if (l % 2) res1 = merge(res1, data[l++]);
      if (r % 2) res2 = merge(data[--r], res2);
      l /= 2;
      r /= 2;
    }
    return merge(res1, res2);
  }
};
void solve() {
  int N, K;
  cin >> N >> K;
  vector<SegmentTree<int>> mi(1 << K, 18), ma(1 << K, 18);
  for (int i = 0; i < N; i++) {
    vector<int> X(K);
    for (int j = 0; j < K; j++) {
      cin >> X[j];
    }
    for (int j = 0; j < 1 << K; j++) {
      int t = 0;
      for (int k = 0; k < K; k++) {
        if (j >> k & 1) {
          t += X[k];
        } else {
          t -= X[k];
        }
      }
      mi[j].update(i, t);
      ma[j].update(i, -t);
    }
  }
  int Q;
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      cin >> i;
      i--;
      vector<int> X(K);
      for (int j = 0; j < K; j++) {
        cin >> X[j];
      }
      for (int j = 0; j < 1 << K; j++) {
        int t = 0;
        for (int k = 0; k < K; k++) {
          if (j >> k & 1) {
            t += X[k];
          } else {
            t -= X[k];
          }
        }
        mi[j].update(i, t);
        ma[j].update(i, -t);
      }
    } else {
      int a, b;
      cin >> a >> b;
      a--;
      int ans = 0;
      for (int j = 0; j < 1 << K; j++) {
        int Mi = mi[j].query(a, b);
        int Ma = -(ma[j].query(a, b));
        ans = max(ans, Ma - Mi);
      }
      cout << ans << endl;
    }
  }
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}
