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>
template <class t>
void maxi(t &x, t y) {
  if (x < y) x = y;
}
template <class t>
void mini(t &x, t y) {
  if (x > y) x = y;
}
using namespace std;
pair<int, int> sg[1 << 5][4 * 200005];
int a[200005][6], n, k;
int apply(int a[], int bit) {
  int v = 0;
  for (int(i) = 0; (i) < (k); (i)++) {
    if ((bit >> i) & 1)
      v -= a[i];
    else
      v += a[i];
  }
  return v;
}
void seg_build(int bit, int l = 1, int r = n + 1, int st = 1) {
  int v = apply(a[l], bit);
  if (r - l < 2) {
    sg[bit][st] = make_pair(v, v);
    return;
  }
  int mid = (l + r) >> 1;
  st <<= 1;
  seg_build(bit, l, mid, st);
  seg_build(bit, mid, r, st + 1);
  pair<int, int> x = sg[bit][st], y = sg[bit][st + 1];
  sg[bit][st >> 1] = make_pair(min(x.first, y.first), max(x.second, y.second));
}
pair<int, int> seg_query(int bit, int a, int b, int l = 1, int r = n + 1,
                         int st = 1) {
  if (l == a && r == b + 1) {
    return sg[bit][st];
  }
  int mid = (l + r) >> 1;
  st <<= 1;
  pair<int, int> ans = make_pair(INT_MAX, INT_MIN);
  if (b < mid) return seg_query(bit, a, b, l, mid, st);
  if (a >= mid) return seg_query(bit, a, b, mid, r, st + 1);
  pair<int, int> x = seg_query(bit, a, mid - 1, l, mid, st);
  pair<int, int> y = seg_query(bit, mid, b, mid, r, st + 1);
  return make_pair(min(x.first, y.first), max(x.second, y.second));
}
void seg_update(int bit, int in, int l = 1, int r = n + 1, int st = 1) {
  if (r - l < 2) {
    int v = apply(a[in], bit);
    sg[bit][st] = make_pair(v, v);
    return;
  }
  int mid = (l + r) >> 1;
  st <<= 1;
  if (in < mid) {
    seg_update(bit, in, l, mid, st);
  } else
    seg_update(bit, in, mid, r, st + 1);
  pair<int, int> x = sg[bit][st], y = sg[bit][st + 1];
  sg[bit][st >> 1] = make_pair(min(x.first, y.first), max(x.second, y.second));
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (int(i) = 1; (i) <= (n); (i)++) {
    for (int(j) = 0; (j) < (k); (j)++) cin >> a[i][j];
  }
  for (int(i) = 0; (i) < (1 << k); (i)++) seg_build(i);
  int q;
  cin >> (q);
  ;
  while (q--) {
    int t;
    cin >> (t);
    ;
    if (t == 1) {
      int i;
      cin >> (i);
      ;
      for (int(j) = 0; (j) < (k); (j)++) cin >> a[i][j];
      for (int(j) = 0; (j) < (1 << k); (j)++) seg_update(j, i);
    } else {
      int l, r;
      cin >> (l) >> (r);
      ;
      int ans = INT_MIN;
      for (int(i) = 0; (i) < (1 << k); (i)++) {
        auto [mi, ma] = seg_query(i, l, r);
        maxi(ans, ma - mi);
      }
      cout << ans << endl;
    }
  }
  return 0;
}
