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;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
int n, k, a[32][200015], b[5][200015], q;
pair<int, int> x[32][800015];
void pushup(int k, int i) {
  int l = i << 1, r = i << 1 | 1;
  x[k][i].first = max(x[k][l].first, x[k][r].first);
  x[k][i].second = min(x[k][l].second, x[k][r].second);
}
void build(int k, int i, int l, int r) {
  if (l == r) {
    x[k][i] = pair<int, int>(a[k][l], a[k][l]);
    return;
  }
  int mi = l + r >> 1;
  build(k, i << 1, l, mi);
  build(k, i << 1 | 1, mi + 1, r);
  pushup(k, i);
}
void update(int k, int i, int l, int r, int p) {
  if (l == p && p == r) {
    x[k][i] = pair<int, int>(a[k][l], a[k][l]);
    return;
  }
  int mi = l + r >> 1;
  if (p <= mi) update(k, i << 1, l, mi, p);
  if (mi < p) update(k, i << 1 | 1, mi + 1, r, p);
  pushup(k, i);
}
pair<int, int> query(int k, int i, int l, int r, int X, int Y) {
  if (X <= l && r <= Y) {
    return x[k][i];
  }
  pair<int, int> res1 = pair<int, int>(-INF, INF),
                 res2 = pair<int, int>(-INF, INF);
  int mi = l + r >> 1;
  if (X <= mi) res1 = query(k, i << 1, l, mi, X, Y);
  if (mi < Y) res2 = query(k, i << 1 | 1, mi + 1, r, X, Y);
  return pair<int, int>(max(res1.first, res2.first),
                        min(res1.second, res2.second));
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < k; ++j) {
      scanf("%d", &b[j][i]);
    }
    for (int j = (1 << k) - 1; ~j; --j) {
      for (int l = 0; l < k; ++l) {
        if (j & 1 << l) {
          a[j][i] += b[l][i];
        } else {
          a[j][i] -= b[l][i];
        }
      }
    }
  }
  for (int i = 0; i < 1 << k; ++i) {
    build(i, 1, 1, n);
  }
  scanf("%d", &q);
  while (q--) {
    int op, l, r;
    scanf("%d", &op);
    if (1 == op) {
      scanf("%d", &l);
      for (int i = 0; i < 1 << k; ++i) {
        a[i][l] = 0;
      }
      for (int i = 0; i < k; ++i) {
        scanf("%d", &b[i][l]);
      }
      for (int i = (1 << k) - 1; ~i; --i) {
        for (int j = 0; j < k; ++j) {
          if (i & 1 << j) {
            a[i][l] += b[j][l];
          } else {
            a[i][l] -= b[j][l];
          }
        }
        update(i, 1, 1, n, l);
      }
    } else {
      scanf("%d%d", &l, &r);
      int ans = 0;
      for (int i = 0; i < 1 << k; ++i) {
        pair<int, int> res = query(i, 1, 1, n, l, r);
        ans = max(ans, res.first - res.second);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
