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 k;
int get(int *a, int m) {
  int i, sum = 0;
  for (i = 0; i < k; ++i)
    if (m & (1 << i))
      sum += a[i];
    else
      sum -= a[i];
  return sum;
}
template <class T>
void pull(T *st, int i, int t) {
  if (t)
    st[i] = min(st[i << 1 | 0], st[i << 1 | 1]);
  else
    st[i] = max(st[i << 1 | 0], st[i << 1 | 1]);
}
template <class T>
void build(T *st, int n, T *a, int t) {
  int n_ = 1;
  while (n_ < n) n_ <<= 1;
  for (int i = 0; i < n; ++i) st[i | n_] = a[i];
  for (int i = n; i < n_; ++i) st[i | n_] = t ? 0x3f3f3f3f : -0x3f3f3f3f;
  for (int i = n_ - 1; i > 0; --i) pull(st, i, t);
  st[0] = n_;
}
template <class T>
void update(T *st, int i, T x, int t) {
  int n_ = st[0];
  st[i |= n_] = x;
  while (i > 1) pull(st, i >>= 1, t);
}
template <class T>
T query(T *st, int l, int r, int t) {
  T aa = t ? 0x3f3f3f3f : -0x3f3f3f3f;
  int n_ = st[0];
  for (l |= n_, r |= n_; l <= r; l >>= 1, r >>= 1) {
    if ((l & 1) == 1) aa = t ? min(aa, st[l++]) : max(aa, st[l++]);
    if ((r & 1) == 0) aa = t ? min(st[r--], aa) : max(st[r--], aa);
  }
  return aa;
}
int main() {
  int n, q, i, j;
  static int a[200000][5];
  static int stmn[(1 << 5)][(1 << 18) << 1], stmx[(1 << 5)][(1 << 18) << 1];
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; ++i)
    for (j = 0; j < k; ++j) scanf("%d", a[i] + j);
  for (i = 0; i < (1 << k); ++i) {
    static int b[200000];
    for (j = 0; j < n; ++j) b[j] = get(a[j], i);
    build(stmn[i], n, b, 1);
    build(stmx[i], n, b, 0);
  }
  scanf("%d", &q);
  while (q--) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d", &i), --i;
      for (j = 0; j < k; ++j) scanf("%d", a[i] + j);
      for (j = 0; j < (1 << k); ++j) {
        t = get(a[i], j);
        update(stmn[j], i, t, 1);
        update(stmx[j], i, t, 0);
      }
    } else {
      int l, r;
      scanf("%d%d", &l, &r), --l, --r;
      int ans = 0;
      for (i = 0; i < (1 << k); ++i)
        ans = max(ans, query(stmx[i], l, r, 0) - query(stmn[i], l, r, 1));
      printf("%d\n", ans);
    }
  }
  return 0;
}
