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 MAXN = 200500;
const int MAXK = 6;
const int INF = (int)1e9;
int k;
struct Node {
  int a[32];
  bool neut = true;
  void in() {
    neut = false;
    int b[5];
    for (int i = (0); i < (int)(k); i++) scanf("%d", &b[i]);
    for (int bm = (0); bm < (int)(1 << k); bm++) {
      a[bm] = 0;
      for (int i = (0); i < (int)(k); i++) {
        int bit = (bool)(bm & (1 << i));
        a[bm] += (bit ? 1 : -1) * b[i];
      }
    }
  }
  int &operator[](int p) { return a[p]; }
  int operator[](int p) const { return a[p]; }
};
int n, q;
Node A[MAXN];
Node mn(const Node &a, const Node &b) {
  if (a.neut) return b;
  if (b.neut) return a;
  Node c;
  c.neut = false;
  for (int i = (0); i < (int)(1 << k); i++) {
    c[i] = min(a[i], b[i]);
  }
  return c;
}
Node mx(const Node &a, const Node &b) {
  if (a.neut) return b;
  if (b.neut) return a;
  Node c;
  c.neut = false;
  for (int i = (0); i < (int)(1 << k); i++) {
    c[i] = max(a[i], b[i]);
  }
  return c;
}
struct STree {
  vector<Node> stmin, stmax;
  int n;
  STree(int n = 0)
      : stmin(4 * n + 5, (Node())), stmax(4 * n + 5, (Node())), n(n) {}
  void init(int k, int s, int e, Node *a) {
    if (s + 1 == e) {
      stmin[k] = a[s];
      stmax[k] = a[s];
      return;
    }
    int m = (s + e) / 2;
    init(2 * k, s, m, a);
    init(2 * k + 1, m, e, a);
    stmin[k] = mn(stmin[2 * k], stmin[2 * k + 1]);
    stmax[k] = mx(stmax[2 * k], stmax[2 * k + 1]);
  }
  void upd(int k, int s, int e, int p, const Node &v) {
    if (s + 1 == e) {
      stmin[k] = v;
      stmax[k] = v;
      return;
    }
    int m = (s + e) / 2;
    if (p < m)
      upd(2 * k, s, m, p, v);
    else
      upd(2 * k + 1, m, e, p, v);
    stmin[k] = mn(stmin[2 * k], stmin[2 * k + 1]);
    stmax[k] = mx(stmax[2 * k], stmax[2 * k + 1]);
  }
  Node query_min(int k, int s, int e, int a, int b) {
    if (s >= b || e <= a) return (Node());
    if (s >= a && e <= b) return stmin[k];
    int m = (s + e) / 2;
    return mn(query_min(2 * k, s, m, a, b), query_min(2 * k + 1, m, e, a, b));
  }
  Node query_max(int k, int s, int e, int a, int b) {
    if (s >= b || e <= a) return (Node());
    if (s >= a && e <= b) return stmax[k];
    int m = (s + e) / 2;
    return mx(query_max(2 * k, s, m, a, b), query_max(2 * k + 1, m, e, a, b));
  }
  void init(Node *a) { init(1, 0, n, a); }
  void upd(int p, const Node &v) { upd(1, 0, n, p, v); }
  Node query_min(int a, int b) { return query_min(1, 0, n, a, b); }
  Node query_max(int a, int b) { return query_max(1, 0, n, a, b); }
};
int main() {
  while (scanf("%d %d", &n, &k) >= 1) {
    STree rmq(n);
    for (int i = (0); i < (int)(n); i++) A[i].in();
    rmq.init(A);
    scanf("%d", &q);
    for (int z = (0); z < (int)(q); z++) {
      int t;
      scanf("%d", &t);
      if (t == 1) {
        int pos;
        scanf("%d", &pos);
        --pos;
        Node b;
        b.in();
        rmq.upd(pos, b);
      } else {
        int l, r;
        scanf("%d %d", &l, &r);
        --l;
        int ans = 0;
        Node a = rmq.query_min(l, r);
        Node b = rmq.query_max(l, r);
        for (int i = (0); i < (int)(1 << k); i++) {
          ans = max(ans, b[i] - a[i]);
        }
        printf("%d\n", ans);
      }
    }
  }
  return 0;
}
