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 int MAXN = 1e6 + 7;
int sum[MAXN][33];
int A[MAXN][33];
int B[MAXN][6];
void Build(int l, int r, int rt, int id) {
  if (l == r) {
    sum[rt][id] = A[l][id];
    return;
  }
  int m = l + r >> 1;
  Build(l, m, rt << 1, id);
  Build(m + 1, r, rt << 1 | 1, id);
  sum[rt][id] = max(sum[rt << 1][id], sum[rt << 1 | 1][id]);
}
void Update(int L, int val, int id, int l, int r, int rt) {
  if (l == r) {
    sum[rt][id] = val;
    return;
  }
  int m = l + r >> 1;
  if (L <= m)
    Update(L, val, id, l, m, rt << 1);
  else
    Update(L, val, id, m + 1, r, rt << 1 | 1);
  sum[rt][id] = max(sum[rt << 1][id], sum[rt << 1 | 1][id]);
}
int Query(int L, int R, int id, int l, int r, int rt) {
  if (L <= l && r <= R) {
    return sum[rt][id];
  }
  int mx = -1e9, m = l + r >> 1;
  if (L <= m) mx = max(Query(L, R, id, l, m, rt << 1), mx);
  if (R > m) mx = max(Query(L, R, id, m + 1, r, rt << 1 | 1), mx);
  return mx;
}
int N, K, M;
int ans[33];
void debugt(int l, int r, int rt, int id) {
  if (l == r) {
    cout << l << ":" << sum[rt][id] << ' ';
    return;
  }
  int m = l + r >> 1;
  debugt(l, m, rt << 1, id);
  debugt(m + 1, r, rt << 1 | 1, id);
}
int main() {
  scanf("%d %d", &N, &K);
  for (int i = (int)1; i <= (int)N; i++) {
    for (int j = (int)1; j <= (int)K; j++) scanf("%d", &B[i][j]);
    for (int j = (int)0; j <= (int)(1 << K) - 1; j++) {
      for (int k = (int)0; k <= (int)K - 1; k++) {
        if (j >> k & 1)
          A[i][j] += B[i][k + 1];
        else
          A[i][j] -= B[i][k + 1];
      }
    }
  }
  for (int j = (int)0; j <= (int)(1 << K) - 1; j++) Build(1, N, 1, j);
  scanf("%d", &M);
  for (int ii = (int)1; ii <= (int)M; ii++) {
    int op, l, r, L;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d", &L);
      for (int j = (int)1; j <= (int)K; j++) scanf("%d", &B[L][j]);
      for (int j = (int)0; j <= (int)(1 << K) - 1; j++) {
        A[L][j] = 0;
        for (int k = (int)0; k <= (int)K - 1; k++) {
          if (j >> k & 1)
            A[L][j] += B[L][k + 1];
          else
            A[L][j] -= B[L][k + 1];
        }
        Update(L, A[L][j], j, 1, N, 1);
      }
    } else {
      scanf("%d %d", &l, &r);
      for (int j = (int)0; j <= (int)(1 << K) - 1; j++) {
        ans[j] = Query(l, r, j, 1, N, 1);
      }
      int res = -1e9;
      for (int j = (int)0; j <= (int)(1 << K) - 1; j++) {
        int tj = (1 << K) - 1 - j;
        res = max(res, ans[j] + ans[tj]);
      }
      printf("%d\n", res);
    }
  }
}
