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 MASK = 36;
const int N = 200010;
int n, k, q, pt[7], s[MASK][N + N], t[MASK][N + N];
void updateMin(int idx, int p, int v) {
  for (s[idx][p += n] = v; p > 1; p >>= 1) {
    s[idx][p >> 1] = min(s[idx][p], s[idx][p ^ 1]);
  }
}
void updateMax(int idx, int p, int v) {
  for (t[idx][p += n] = v; p > 1; p >>= 1) {
    t[idx][p >> 1] = max(t[idx][p], t[idx][p ^ 1]);
  }
}
int getMin(int idx, int l, int r) {
  int ans = INT_MAX;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ans = min(ans, s[idx][l++]);
    if (r & 1) ans = min(ans, s[idx][--r]);
  }
  return ans;
}
int getMax(int idx, int l, int r) {
  int ans = INT_MIN;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ans = max(ans, t[idx][l++]);
    if (r & 1) ans = max(ans, t[idx][--r]);
  }
  return ans;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      scanf("%d", pt + j);
    }
    for (int mask = 0; mask < 1 << k; ++mask) {
      int cur = 0;
      for (int j = 0; j < k; ++j) {
        if (mask & 1 << j)
          cur += pt[j];
        else
          cur -= pt[j];
      }
      updateMin(mask, i, cur);
      updateMax(mask, i, cur);
    }
  }
  cin >> q;
  while (q--) {
    int cmd;
    scanf("%d", &cmd);
    if (cmd == 1) {
      int at;
      scanf("%d", &at);
      --at;
      for (int j = 0; j < k; ++j) scanf("%d", pt + j);
      for (int mask = 0; mask < 1 << k; ++mask) {
        int cur = 0;
        for (int j = 0; j < k; ++j) {
          if (mask & 1 << j)
            cur += pt[j];
          else
            cur -= pt[j];
        }
        updateMin(mask, at, cur);
        updateMax(mask, at, cur);
      }
    } else {
      int l, r, ans = 0;
      scanf("%d %d", &l, &r);
      --l;
      for (int mask = 0; mask < 1 << k; ++mask) {
        ans = max(ans, getMax(mask, l, r) - getMin(mask, l, r));
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
