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;
bool debug = 1;
const int N = 2e5 + 10;
int seg[2][1 << 5][2 * N];
int v[2 * N][5];
int n;
void build(int k) {
  for (int mask = 0; mask < 1 << k; mask++) {
    for (int cor = 0; cor < 2; cor++) {
      int *s = seg[cor][mask];
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < k; j++) {
          if ((1 << j) & mask)
            s[i + n] += v[i][j];
          else
            s[i + n] -= v[i][j];
        }
      }
      if (cor)
        for (int i = n - 1; i >= 1; i--)
          for (int id = 0; id < k; id++) s[i] = max(s[i << 1], s[i << 1 | 1]);
      else
        for (int i = n - 1; i >= 1; i--)
          for (int id = 0; id < k; id++) s[i] = min(s[i << 1], s[i << 1 | 1]);
    }
  }
}
int qry(int lo, int ro, int k) {
  int ans = 0, l, r;
  for (int mask = 0; mask < 1 << k; mask++) {
    int *s = seg[1][mask];
    int ans_max = -INT_MAX;
    l = lo, r = ro;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ans_max = max(s[l++], ans_max);
      if (r & 1) ans_max = max(s[--r], ans_max);
    }
    int ans_min = INT_MAX;
    s = seg[0][mask];
    l = lo, r = ro;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ans_min = min(s[l++], ans_min);
      if (r & 1) ans_min = min(s[--r], ans_min);
    }
    ans = max(ans, ans_max - ans_min);
  }
  return ans;
}
void up(int id, int k, vector<int> val) {
  for (int i = 0; i < k; i++) v[id][i] = val[i];
  for (int mask = 0; mask < 1 << k; mask++) {
    for (int cor = 0; cor < 2; cor++) {
      int *s = seg[cor][mask];
      s[id + n] = 0;
      for (int i = 0; i < k; i++) {
        if ((1 << i) & mask)
          s[id + n] += v[id][i];
        else
          s[id + n] -= v[id][i];
      }
      int pos = id;
      for (pos += n; pos > 1; pos >>= 1) {
        if (cor)
          s[pos >> 1] = max(s[pos], s[pos ^ 1]);
        else
          s[pos >> 1] = min(s[pos], s[pos ^ 1]);
      }
    }
  }
}
int k;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) scanf("%d", v[i] + j);
  }
  build(k);
  int q;
  scanf("%d", &q);
  for (int qq = 0; qq < q; qq++) {
    char t;
    scanf(" %c", &t);
    if (t == '1') {
      int id;
      scanf("%d", &id);
      vector<int> vv;
      for (int i = 0; i < k; i++) {
        int x;
        scanf("%d", &x);
        vv.push_back(x);
      }
      up(id - 1, k, vv);
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      l--;
      printf("%d\n", qry(l, r, k));
    }
  }
  return 0;
}
