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 n = 2 * 256 * 1024;
const int offset = n / 2 - 1;
int T[n][32];
int P[5];
int R[32], R2[32];
int N, K, K2, Q;
int leftN(int i) { return 2 * i + 1; }
int rightN(int i) { return 2 * i + 2; }
int parentN(int i) { return (i - 1) / 2; }
void setP(int i) {
  fill_n(T[offset + i], K2 * 2, 0);
  for (int k = 0; k < K; ++k) {
    int x = P[k];
    for (int j = 0; j < K2; ++j) {
      if (((j >> k) & 1) == 1)
        T[offset + i][j] -= x;
      else
        T[offset + i][j] += x;
    }
    for (int j = 0; j < K2; ++j) {
      if (((j >> k) & 1) == 1)
        T[offset + i][j + K2] -= x;
      else
        T[offset + i][j + K2] += x;
    }
  }
}
void combine(int l, int r) {
  for (int i = 0; i < K2; ++i) {
    R[i] = min(T[l][i], T[r][i]);
  }
  for (int i = 0; i < K2; ++i) {
    R[K2 + i] = max(T[l][K2 + i], T[r][K2 + i]);
  }
}
void update(int i) {
  combine(leftN(i), rightN(i));
  for (int j = 0; j < 2 * K2; ++j) T[i][j] = R[j];
  if (i != 0) update(parentN(i));
}
vector<int> query(int l, int r, int i = 0, int j = offset, int cur = 0) {
  vector<int> R(2 * K2);
  if (i >= l && j <= r) {
    for (int k = 0; k < 2 * K2; ++k) R[k] = T[cur][k];
    return R;
  }
  if (j < l || i > r) {
    for (int k = 0; k < 2 * K2; ++k) R[k] = (k < K2 ? 1000000000 : -1000000000);
    return R;
  }
  int m = (i + j) / 2;
  vector<int> R2 = query(l, r, i, m, leftN(cur));
  R = query(l, r, m + 1, j, rightN(cur));
  for (int k = 0; k < K2; ++k) {
    R[k] = min(R[k], R2[k]);
  }
  for (int k = 0; k < K2; ++k) {
    R[k + K2] = max(R[k + K2], R2[k + K2]);
  }
  return R;
}
void built() {
  for (int i = offset - 1; i >= 0; --i) {
    combine(leftN(i), rightN(i));
    for (int j = 0; j < 2 * K2; ++j) T[i][j] = R[j];
  }
}
int main() {
  cin >> N >> K;
  K2 = 1 << (K - 1);
  for (int i = 0; i < n; ++i) {
    for (int k = 0; k < K2 * 2; ++k)
      T[i][k] = (k < K2 ? 1000000000 : -1000000000);
  }
  for (int i = 0; i < N; ++i) {
    for (int k = 0; k < K; ++k) {
      cin >> P[k];
    }
    setP(i);
  }
  built();
  for (int i = 0; i < n; ++i) {
  }
  cin >> Q;
  for (int q = 0; q < Q; ++q) {
    int w;
    cin >> w;
    if (w == 1) {
      int i;
      cin >> i;
      i--;
      for (int k = 0; k < K; ++k) {
        cin >> P[k];
      }
      setP(i);
      update(parentN(offset + i));
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      vector<int> R = query(l, r);
      int res = 0;
      for (int k = 0; k < K2; ++k) res = max(res, R[k + K2] - R[k]);
      cout << res << "\n";
    }
  }
  return 0;
}
