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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int x, int y) {
  ++y;
  return (rng() % (y - x)) + x;
}
int n, k, A[300006][5], q;
struct node {
  int second, e, m, mav, miv;
  node *l, *r;
  node(int _s, int _e) {
    second = _s, e = _e, m = (second + e) / 2, mav = 0, miv = (long long)1e18;
    if (second != e) {
      l = new node(second, m);
      r = new node(m + 1, e);
    }
  }
  void update(int x, int nv) {
    if (second == e) {
      mav = nv;
      miv = nv;
      return;
    }
    if (x > m)
      r->update(x, nv);
    else
      l->update(x, nv);
    mav = max(l->mav, r->mav);
    miv = min(l->miv, r->miv);
  }
  pair<int, pair<int, int> > rmq(int x, int y) {
    if (second == x && e == y)
      return pair<int, pair<int, int> >(mav - miv, pair<int, int>(mav, miv));
    if (x > m)
      return r->rmq(x, y);
    else if (y <= m)
      return l->rmq(x, y);
    else {
      pair<int, pair<int, int> > L = l->rmq(x, m);
      int a = L.second.first, b = L.second.second;
      pair<int, pair<int, int> > R = r->rmq(m + 1, y);
      int c = R.second.first, d = R.second.second;
      return max({pair<int, pair<int, int> >(a - d, pair<int, int>(a, d)), L, R,
                  pair<int, pair<int, int> >(c - b, pair<int, int>(c, b))});
    }
  }
} * seg[(1 << 5)];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < k; j++) cin >> A[i][j];
  for (int i = 0; i <= (1 << (k - 1)); i++) {
    seg[i] = new node(0, n - 1);
    for (int j = 0; j < n; j++) {
      int ans = 0;
      for (int K = 0; K < k; K++) {
        ans += ((((1 << K) & i) ? 1 : -1) * A[j][K]);
      }
      seg[i]->update(j, ans);
    }
  }
  cin >> q;
  for (int Q = 0; Q < q; Q++) {
    int op;
    cin >> op;
    if (op == 1) {
      int i;
      cin >> i;
      --i;
      for (int j = 0; j < k; j++) cin >> A[i][j];
      int j = i;
      for (int i = 0; i <= (1 << (k - 1)); i++) {
        int ans = 0;
        for (int K = 0; K < k; K++) {
          ans += ((((1 << K) & i) ? 1 : -1) * A[j][K]);
        }
        seg[i]->update(j, ans);
      }
    } else {
      int l, r;
      cin >> l >> r;
      --l, --r;
      int ans = 0;
      for (int i = 0; i <= (1 << (k - 1)); i++) {
        ans = max(ans, seg[i]->rmq(l, r).first);
      }
      cout << ans << "\n";
    }
  }
}
