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>
int faster_in() {
  int r = 0, c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') return -faster_in();
  for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
    ;
  return r;
}
using namespace std;
const int INF = int(1e9 + 7);
const int tam = 200010;
pair<int, int> T[4 * tam][(1 << 5)];
int B[tam][5];
int n, k;
int getSum(int i, int mask) {
  int res = 0;
  for (int j = 0; j < k; j++) {
    if (((1 << j) & mask))
      res += B[i][j];
    else
      res -= B[i][j];
  }
  return res;
}
void init(int b, int e, int nodo, int mask) {
  int L = 2 * nodo + 1, R = L + 1, mid = (b + e) / 2;
  if (b == e) {
    T[nodo][mask] = make_pair(getSum(b, mask), getSum(b, mask));
    return;
  }
  init(b, mid, L, mask);
  init(mid + 1, e, R, mask);
  T[nodo][mask].first = min(T[L][mask].first, T[R][mask].first);
  T[nodo][mask].second = max(T[L][mask].second, T[R][mask].second);
}
void update(int b, int e, int nodo, int mask, int pos) {
  int L = 2 * nodo + 1, R = L + 1, mid = (b + e) / 2;
  if (b == e) {
    T[nodo][mask] = make_pair(getSum(b, mask), getSum(b, mask));
    return;
  }
  if (pos <= mid)
    update(b, mid, L, mask, pos);
  else
    update(mid + 1, e, R, mask, pos);
  T[nodo][mask].first = min(T[L][mask].first, T[R][mask].first);
  T[nodo][mask].second = max(T[L][mask].second, T[R][mask].second);
}
pair<int, int> query(int b, int e, int nodo, int mask, int i, int j) {
  int L = 2 * nodo + 1, R = L + 1, mid = (b + e) / 2;
  if (i <= b && e <= j) return T[nodo][mask];
  if (j <= mid)
    return query(b, mid, L, mask, i, j);
  else if (i > mid)
    return query(mid + 1, e, R, mask, i, j);
  else {
    pair<int, int> rl, rr, r;
    rl = query(b, mid, L, mask, i, j);
    rr = query(mid + 1, e, R, mask, i, j);
    r.first = min(rl.first, rr.first);
    r.second = max(rl.second, rr.second);
    return r;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      cin >> B[i][j];
    }
  }
  for (int mask = 0; mask < (1 << k); mask++) {
    init(0, n - 1, 0, mask);
  }
  int q;
  cin >> q;
  while (q--) {
    int op;
    cin >> op;
    if (op == 1) {
      int idx;
      cin >> idx;
      idx--;
      for (int i = 0; i < k; i++) {
        cin >> B[idx][i];
      }
      for (int mask = 0; mask < (1 << k); mask++) {
        update(0, n - 1, 0, mask, idx);
      }
    } else {
      int i, j;
      cin >> i >> j;
      i--;
      j--;
      int best = 0;
      for (int mask = 0; mask < (1 << k); mask++) {
        pair<int, int> res = query(0, n - 1, 0, mask, i, j);
        best = max(best, res.second - res.first);
      }
      cout << best << '\n';
    }
  }
  return 0;
}
