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 = 2e5 + 5;
const long long inf = 1e15;
int n, k;
vector<int> p[N];
long long IT[32][4 * N];
long long val(int i, int bm) {
  long long sum = 0;
  for (int j = 0; j < k; ++j) {
    if (bm & (1 << j))
      sum += p[i][j];
    else
      sum -= p[i][j];
  }
  return sum;
}
void BuildTree(long long tree[], int bm, int id, int l, int r) {
  if (l == r) {
    tree[id] = val(l, bm);
    return;
  }
  int mid = (l + r) >> 1;
  BuildTree(tree, bm, id * 2, l, mid);
  BuildTree(tree, bm, id * 2 + 1, mid + 1, r);
  tree[id] = max(tree[id * 2], tree[id * 2 + 1]);
}
void upd(long long tree[], int bm, int id, int l, int r, int idx) {
  if (idx <= l && r <= idx) {
    tree[id] = val(l, bm);
    return;
  }
  int mid = (l + r) >> 1;
  if (idx <= mid)
    upd(tree, bm, id * 2, l, mid, idx);
  else
    upd(tree, bm, id * 2 + 1, mid + 1, r, idx);
  tree[id] = max(tree[id * 2], tree[id * 2 + 1]);
}
long long qry(long long tree[], int id, int l, int r, int u, int v) {
  if (u <= l && r <= v) return tree[id];
  int mid = (l + r) >> 1;
  long long ans = -inf;
  if (u <= mid) ans = max(ans, qry(tree, id << 1, l, mid, u, v));
  if (v > mid) ans = max(ans, qry(tree, (id << 1) + 1, mid + 1, r, u, v));
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    int u;
    for (int j = 1; j <= k; ++j) {
      scanf("%d", &u);
      p[i].push_back(u);
    }
  }
  for (int bm = 0; bm < (1 << k); ++bm) BuildTree(IT[bm], bm, 1, 1, n);
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int qt;
    scanf("%d", &qt);
    if (qt == 1) {
      int idx;
      vector<int> np;
      scanf("%d", &idx);
      for (int j = 1; j <= k; ++j) {
        int u;
        scanf("%d", &u);
        np.push_back(u);
      }
      p[idx] = np;
      for (int bm = 0; bm < (1 << k); ++bm) upd(IT[bm], bm, 1, 1, n, idx);
    } else {
      long long ans = -inf;
      int l, r;
      scanf("%d%d", &l, &r);
      for (int bm = 0; bm < (1 << k) / 2; ++bm) {
        long long tmp = qry(IT[bm], 1, 1, n, l, r) +
                        qry(IT[(1 << k) - 1 - bm], 1, 1, n, l, r);
        ans = max(tmp, ans);
      }
      printf("%I64d\n", ans);
      fflush(stdout);
    }
  }
  return 0;
}
