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 mod = 1e9 + 7;
const int N = 2e5 + 5, M = 35;
int n, m, a[N][M], k, lim;
class Tree {
 public:
  int mn, mx;
  Tree() {}
  inline Tree(const int &mn, const int &mx) : mn(mn) { this->mx = mx; }
  inline Tree(const int &cast) { mn = mx = cast; }
  inline Tree operator+(const Tree &);
} tree[4 * N][M];
class Function {
 private:
  void bitMasking(const int *, const int &) const;

 public:
  void build(const int &, const int &, const int &) const;
  void update(const int &, const int &, const int &, const int *,
              const int &) const;
  Tree query(const int &, const int &, const int &, const int &, const int &,
             const int &) const;
};
inline Tree Tree::operator+(const Tree &a) {
  Tree temp = Tree(0, 0);
  temp.mn = min(mn, a.mn);
  temp.mx = max(mx, a.mx);
  return temp;
}
void Function::bitMasking(const int *arr, const int &node) const {
  for (int i = 0; i < lim; ++i) {
    int val = 0;
    for (int j = 0; j < k; ++j) {
      if (i & (1 << j))
        val += arr[j];
      else
        val -= arr[j];
    }
    tree[node][i] = val;
  }
}
void Function::build(const int &st, const int &end, const int &node) const {
  if (st == end) {
    bitMasking(a[st], node);
    return;
  }
  int mid = (st + end) >> 1;
  build(st, mid, 2 * node);
  build(mid + 1, end, 2 * node + 1);
  for (int i = 0; i < lim; ++i)
    tree[node][i] = tree[2 * node][i] + tree[2 * node + 1][i];
}
void Function::update(const int &st, const int &end, const int &ind,
                      const int val[], const int &node) const {
  if (st == end) {
    bitMasking(val, node);
    return;
  }
  int mid = (st + end) >> 1;
  if (ind <= mid)
    update(st, mid, ind, val, 2 * node);
  else
    update(mid + 1, end, ind, val, 2 * node + 1);
  for (int i = 0; i < lim; ++i)
    tree[node][i] = tree[2 * node][i] + tree[2 * node + 1][i];
}
Tree Function::query(const int &st, const int &end, const int &qs,
                     const int &qe, const int &mask, const int &node) const {
  if (st > qe || end < qs) return Tree(2e9 + 7, -2e9 + 7);
  if (st >= qs && end <= qe) return tree[node][mask];
  int mid = (st + end) >> 1;
  Tree left = query(st, mid, qs, qe, mask, 2 * node);
  Tree right = query(mid + 1, end, qs, qe, mask, 2 * node + 1);
  Tree temp = left + right;
  return temp;
}
int main() {
  int test;
  test = 1;
  for (int tt = 1; tt <= test; ++tt) {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < k; ++j) scanf("%d", &a[i][j]);
    lim = (1 << k);
    Function *obj = new Function();
    obj->build(0, n - 1, 1);
    int q;
    scanf("%d", &q);
    while (q--) {
      int type;
      scanf("%d", &type);
      if (type == 1) {
        int ind, val[k];
        scanf("%d", &ind);
        for (int i = 0; i < k; ++i) scanf("%d", &val[i]);
        obj->update(0, n - 1, ind - 1, val, 1);
      } else {
        int l, r, ans = 0;
        scanf("%d %d", &l, &r);
        for (int i = 0; i < lim; ++i) {
          Tree temp = obj->query(0, n - 1, l - 1, r - 1, i, 1);
          ans = max(ans, temp.mx - temp.mn);
        }
        printf("%d\n", ans);
      }
    }
  }
  return 0;
}
