You are given an array a of n points in k-dimensional space. Let the distance between two points a_x and a_y be ∑ _{i = 1}^{k} |a_{x, i} - a_{y, i}| (it is also known as Manhattan distance).

You have to process q queries of the following two types:

  * 1 i b_1 b_2 ... b_k — set i-th element of a to the point (b_1, b_2, ..., b_k);
  * 2 l r — find the maximum distance between two points a_i and a_j, where l ≤ i, j ≤ r.

Input

The first line contains two numbers n and k (1 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ k ≤ 5) — the number of elements in a and the number of dimensions of the space, respectively.

Then n lines follow, each containing k integers a_{i, 1}, a_{i, 2}, ..., a_{i, k} (-10^6 ≤ a_{i, j} ≤ 10^6) — the coordinates of i-th point.

The next line contains one integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries.

Then q lines follow, each denoting a query. There are two types of queries:

  * 1 i b_1 b_2 ... b_k (1 ≤ i ≤ n, -10^6 ≤ b_j ≤ 10^6) — set i-th element of a to the point (b_1, b_2, ..., b_k);
  * 2 l r (1 ≤ l ≤ r ≤ n) — find the maximum distance between two points a_i and a_j, where l ≤ i, j ≤ r.



There is at least one query of the second type.

Output

Print the answer for each query of the second type.

Example

Input


5 2
1 2
2 3
3 4
4 5
5 6
7
2 1 5
2 1 3
2 3 5
1 5 -1 -2
2 1 5
1 4 -1 -2
2 1 5


Output


8
4
4
12
10
#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;
}
