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 MAX(int a, int b) { return (a > b) ? a : b; }
int MIN(int a, int b) { return (a < b) ? a : b; }
int ABS(int x) { return (x > 0) ? x : -x; }
int left(int x) { return (x << 1); }
int right(int x) { return (x << 1) + 1; }
int lsone(int x) { return (x & (-x)); }
const int INF = 1e8;
const int maxn = 2e5 + 5;
int n, k, q, typ;
int a[maxn][10];
pair<int, int> st[32][4 * maxn];
int getVal(int idx, int mask) {
  int tmp = 0;
  for (int i = 0; i < k; i++) {
    if ((mask & (1 << i)) == 0) {
      tmp -= a[idx][i];
    } else {
      tmp += a[idx][i];
    }
  }
  return tmp;
}
void build(int i, int p, int l, int r) {
  if (l == r) {
    st[i][p] = pair<int, int>(getVal(l, i), getVal(l, i));
  } else {
    int mid = (l + r) / 2;
    build(i, left(p), l, mid);
    build(i, right(p), mid + 1, r);
    st[i][p] =
        pair<int, int>(MIN(st[i][left(p)].first, st[i][right(p)].first),
                       MAX(st[i][left(p)].second, st[i][right(p)].second));
  }
}
pair<int, int> query(int lvl, int p, int l, int r, int i, int j) {
  if (l > j || r < i) {
    return pair<int, int>(INF, -INF);
  }
  if (l >= i && r <= j) return st[lvl][p];
  int mid = (l + r) / 2;
  pair<int, int> p1 = query(lvl, left(p), l, mid, i, j);
  pair<int, int> p2 = query(lvl, right(p), mid + 1, r, i, j);
  return pair<int, int>(MIN(p1.first, p2.first), MAX(p1.second, p2.second));
}
void update(int lvl, int p, int l, int r, int idx, int val) {
  if (l > idx || r < idx) return;
  if (l == r) {
    st[lvl][p] = pair<int, int>(val, val);
  } else {
    long long int mid = (l + r) / 2;
    update(lvl, left(p), l, mid, idx, val);
    update(lvl, right(p), mid + 1, r, idx, val);
    pair<int, int> p1 = st[lvl][left(p)], p2 = st[lvl][right(p)];
    st[lvl][p] =
        pair<int, int>(MIN(p1.first, p2.first), MAX(p1.second, p2.second));
  }
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 0; i < (1 << k); i++) {
    build(i, 1, 0, n - 1);
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &typ);
    if (typ == 1) {
      int idx;
      scanf("%d", &idx);
      idx--;
      for (int i = 0; i < k; i++) {
        scanf("%d", &a[idx][i]);
      }
      for (int i = 0; i < (1 << k); i++) {
        update(i, 1, 0, n - 1, idx, getVal(idx, i));
      }
    } else {
      int le, ri, ans = 0;
      scanf("%d %d", &le, &ri);
      le--;
      ri--;
      for (int i = 0; i < (1 << k); i++) {
        pair<int, int> tmpAns = query(i, 1, 0, n - 1, le, ri);
        ans = MAX(ans, tmpAns.second - tmpAns.first);
      }
      printf("%d\n", ans);
    }
  }
}
