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 = 200100;
const int INF = 1e9;
struct STree {
  vector<int> st;
  int n;
  STree(int n = 0) : st(4 * n + 5, -INF), n(n) {}
  void init(int k, int s, int e, int *a) {
    if (s + 1 == e) {
      st[k] = a[s];
      return;
    }
    int m = (s + e) / 2;
    init(2 * k, s, m, a);
    init(2 * k + 1, m, e, a);
    st[k] = max(st[2 * k], st[2 * k + 1]);
  }
  void upd(int k, int s, int e, int p, int v) {
    if (s + 1 == e) {
      st[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);
    st[k] = max(st[2 * k], st[2 * k + 1]);
  }
  int query(int k, int s, int e, int a, int b) {
    if (s >= b || e <= a) return -INF;
    if (s >= a && e <= b) return st[k];
    int m = (s + e) / 2;
    return max(query(2 * k, s, m, a, b), query(2 * k + 1, m, e, a, b));
  }
  void init(int *a) { init(1, 0, n, a); }
  void upd(int p, int v) { upd(1, 0, n, p, v); }
  int query(int a, int b) { return query(1, 0, n, a, b); }
} R[40];
int n, k, A[40][MAXN];
int val(vector<int> &V, int bm) {
  int ans = 0;
  for (int i = (0); i < (int)(k); i++) {
    ans = ans + V[i] * ((bm & (1 << i)) ? -1 : 1);
  }
  return ans;
}
int main() {
  while (scanf("%d %d", &n, &k) >= 1) {
    for (int i = (0); i < (int)((1 << k)); i++) R[i] = STree(n);
    for (int i = (0); i < (int)(n); i++) {
      vector<int> V(k);
      for (int j = (0); j < (int)(k); j++) scanf("%d", &V[j]);
      for (int j = (0); j < (int)((1 << k)); j++) A[j][i] = val(V, j);
    }
    for (int i = (0); i < (int)((1 << k)); i++) R[i].init(A[i]);
    int q;
    scanf("%d", &q);
    for (int cs = (0); cs < (int)(q); cs++) {
      int tp;
      scanf("%d", &tp);
      if (tp == 1) {
        int id;
        vector<int> V(k);
        scanf("%d", &id);
        for (int j = (0); j < (int)(k); j++) scanf("%d", &V[j]);
        id--;
        for (int j = (0); j < (int)((1 << k)); j++) R[j].upd(id, val(V, j));
      } else {
        int ans = 0, l, r;
        scanf("%d %d", &l, &r);
        l--;
        for (int i = (0); i < (int)((1 << k)); i++) {
          int a = R[i].query(l, r);
          int b = R[(1 << k) - 1 - i].query(l, r);
          ans = max(ans, a + b);
        }
        printf("%d\n", ans);
      }
    }
  }
  return 0;
}
