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;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
template <class T>
class ST {
  vector<T> A;
  vi st;
  int n;

 public:
  ST() {}
  void make(int n) {
    this->n = n;
    A.resize(n);
    st.assign(4 * n, 0);
    build(1, 0, n - 1);
  }
  int rmq(int i, int j) { return A[rmq(1, 0, n - 1, i, j)]; }
  void update(int i, T v) {
    A[i] = v;
    update(1, 0, n - 1, i);
  }

 private:
  int left(int p) { return p << 1; }
  int right(int p) { return (p << 1) + 1; }
  void build(int p, int L, int R) {
    if (L == R)
      st[p] = L;
    else {
      build(left(p), L, (L + R) / 2);
      build(right(p), (L + R) / 2 + 1, R);
      int p1 = st[left(p)], p2 = st[right(p)];
      st[p] = (A[p1] <= A[p2]) ? p1 : p2;
    }
  }
  int rmq(int p, int L, int R, int i, int j) {
    if (i > R || j < L) return -1;
    if (L >= i && R <= j) return st[p];
    int p1 = rmq(left(p), L, (L + R) / 2, i, j);
    int p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j);
    if (p1 == -1) return p2;
    if (p2 == -1) return p1;
    return (A[p1] <= A[p2]) ? p1 : p2;
  }
  void update(int p, int L, int R, int i) {
    if (L == R) return;
    if (i <= (L + R) / 2)
      update(left(p), L, (L + R) / 2, i);
    else
      update(right(p), (L + R) / 2 + 1, R, i);
    st[p] = A[st[right(p)]] <= A[st[left(p)]] ? st[right(p)] : st[left(p)];
  }
};
ST<int> st[32];
int n, k;
void upd(int i) {
  vi a(k);
  for (int j = 0; j < k; ++j) cin >> a[j];
  for (int j = 0; j < 1 << k; ++j) {
    int sum = 0;
    for (int l = 0; l < k; ++l) {
      if (j & (1 << l))
        sum += a[l];
      else
        sum -= a[l];
    }
    st[j].update(i, sum);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int j = 0; j < 1 << k; ++j) st[j].make(n);
  for (int i = 0; i < n; ++i) upd(i);
  int q;
  cin >> q;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      cin >> i;
      upd(i - 1);
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      int bst = 0;
      for (int j = 0; j < 1 << k; ++j) {
        int a = st[j].rmq(l, r);
        int b = st[j ^ ((1 << k) - 1)].rmq(l, r);
        bst = max(bst, abs(a + b));
      }
      cout << bst << '\n';
    }
  }
}
