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 MOD = 1000000007;
vector<int> dr[800000];
vector<int> dr2[800000];
int k, kk;
vector<int> a[800000];
vector<int> iz;
int f(int c, vector<int> aa) {
  int c2 = c, ans = 0;
  for (int j = 0; j < k; j++) {
    if (c2 % 2 == 0) {
      ans += aa[j];
    } else {
      ans -= aa[j];
    }
    c2 /= 2;
  }
  return ans;
}
void bl(int v, int l, int r) {
  if (r - l == 1) {
    for (int i = 0; i < kk; i++) {
      dr[v].resize(kk);
      dr2[v].resize(kk);
      dr[v][i] = f(i, a[l]);
      dr2[v][i] = f(i, a[l]);
    }
    return;
  }
  bl(2 * v + 1, l, (l + r) / 2);
  bl(2 * v + 2, (l + r) / 2, r);
  dr[v].resize(kk);
  dr2[v].resize(kk);
  for (int i = 0; i < kk; i++) {
    dr[v][i] = max(dr[2 * v + 1][i], dr[2 * v + 2][i]);
    dr2[v][i] = min(dr2[2 * v + 1][i], dr2[2 * v + 2][i]);
  }
}
vector<int> mx(int v, int l, int r, int ln, int rn) {
  if (r <= ln || rn <= l) {
    vector<int> ttt(kk);
    for (int i = 0; i < kk; i++) {
      ttt[i] = -MOD;
    }
    return ttt;
  }
  if (ln <= l && r <= rn) {
    return dr[v];
  }
  vector<int> a1 = mx(2 * v + 1, l, (l + r) / 2, ln, rn);
  vector<int> a2 = mx(2 * v + 2, (l + r) / 2, r, ln, rn);
  vector<int> a3(kk);
  for (int i = 0; i < kk; i++) {
    a3[i] = max(a1[i], a2[i]);
  }
  return a3;
}
vector<int> mn(int v, int l, int r, int ln, int rn) {
  if (r <= ln || rn <= l) {
    vector<int> ttt(kk);
    for (int i = 0; i < kk; i++) {
      ttt[i] = MOD;
    }
    return ttt;
  }
  if (ln <= l && r <= rn) {
    return dr2[v];
  }
  vector<int> a1 = mn(2 * v + 1, l, (l + r) / 2, ln, rn);
  vector<int> a2 = mn(2 * v + 2, (l + r) / 2, r, ln, rn);
  vector<int> a3(kk);
  for (int i = 0; i < kk; i++) {
    a3[i] = min(a1[i], a2[i]);
  }
  return a3;
}
void gt(int v, int l, int r, int id) {
  if (id < l || id >= r) {
    return;
  }
  if (l == r - 1) {
    dr[v] = iz;
    dr2[v] = iz;
    return;
  }
  gt(2 * v + 1, l, (l + r) / 2, id);
  gt(2 * v + 2, (l + r) / 2, r, id);
  dr[v].resize(kk);
  dr2[v].resize(kk);
  for (int i = 0; i < kk; i++) {
    dr[v][i] = max(dr[2 * v + 1][i], dr[2 * v + 2][i]);
    dr2[v][i] = min(dr2[2 * v + 1][i], dr2[2 * v + 2][i]);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n >> k;
  kk = (int)(pow(2, k));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      int r;
      cin >> r;
      a[i].push_back(r);
    }
  }
  bl(0, 0, n);
  int q;
  cin >> q;
  while (q--) {
    int c;
    cin >> c;
    if (c == 1) {
      int idd;
      cin >> idd;
      idd--;
      iz.resize(kk);
      vector<int> izz(k);
      for (int j = 0; j < k; j++) {
        cin >> izz[j];
        a[idd][j] = izz[j];
      }
      for (int j = 0; j < kk; j++) {
        iz[j] = f(j, a[idd]);
      }
      gt(0, 0, n, idd);
    } else {
      int L, R;
      cin >> L >> R;
      int mxx = -MOD;
      vector<int> mem = mx(0, 0, n, L - 1, R);
      vector<int> mem2 = mn(0, 0, n, L - 1, R);
      for (int i = 0; i < kk; i++) {
        mxx = max(mxx, mem[i] - mem2[i]);
      }
      cout << mxx << endl;
    }
  }
}
