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;
int n, k, sum, p[200009][7], stt[34][200009], q, t, ind, l, r;
const int M = 1e9 + 7;
class seg_min {
 private:
  pair<int, int> st[200009 + 200009 + 200009 + 200009];

 public:
  void build(int *a, int node = 1, int l = 1, int r = 200009 - 1) {
    if (l > r) return;
    if (l == r)
      st[node] = make_pair(a[l], a[l]);
    else {
      build(a, node + node, l, (l + r >> 1));
      build(a, node + 1 + node, (l + r >> 1) + 1, r);
      int L = node + node;
      int R = L + 1;
      st[node] = make_pair(min(st[L].first, st[R].first),
                           max(st[L].second, st[R].second));
    }
  }
  void update(int x, int v, int node = 1, int l = 1, int r = 200009 - 1) {
    if (l > r or x > r or x < l) return;
    if (l == r)
      st[node] = make_pair(v, v);
    else {
      int L = node << 1;
      int R = L + 1;
      int mid = l + r >> 1;
      update(x, v, L, l, mid);
      update(x, v, R, mid + 1, r);
      st[node] = make_pair(min(st[L].first, st[R].first),
                           max(st[L].second, st[R].second));
    }
  }
  pair<int, int> query(int ql, int qr, int node = 1, int l = 1,
                       int r = 200009 - 1) {
    if (l > r or ql > r or qr < l) return make_pair(INT_MAX, INT_MIN);
    if (l >= ql and r <= qr)
      return st[node];
    else {
      pair<int, int> L = query(ql, qr, node + node, l, (l + r >> 1));
      pair<int, int> R = query(ql, qr, node + 1 + node, (l + r >> 1) + 1, r);
      return make_pair(min(L.first, R.first), max(L.second, R.second));
    }
  }
} st[34];
int32_t main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    for (int ii = 1; ii <= k; ii++) scanf("%d", &p[i][ii]);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < (1 << k); j++) {
      sum = 0;
      for (int dim = 1; dim <= k; dim++)
        sum += (((j >> dim - 1) & 1) ? -p[i][dim] : p[i][dim]);
      stt[j][i] = sum;
    }
  for (int i = 0; i < (1 << k); i++) st[i].build(stt[i]);
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &ind);
      for (int i = 1; i <= k; i++) scanf("%d", &p[ind][i]);
      for (int i = 0; i < (1 << k); i++) {
        sum = 0;
        for (int j = 1; j <= k; j++)
          sum += (((i >> j - 1) & 1) ? -p[ind][j] : p[ind][j]);
        st[i].update(ind, sum);
      }
    } else {
      scanf("%d%d", &l, &r);
      sum = 0;
      for (int i = 0; i < (1 << k); i++) {
        pair<int, int> ha = st[i].query(l, r);
        sum = max(sum, ha.second - ha.first);
      }
      printf("%d\n", sum);
    }
  }
}
