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 long double EPS = 1e-9;
int a[400100][6];
int tree[400100][1 << 5];
int n, k;
int calc_best(const int* arr1, const int* arr2) {
  int res = 0;
  for (int mask = 0; mask < (1 << k); mask++) {
    int cur = 0;
    int cmask = ((1 << k) - 1) ^ mask;
    for (int j = 0; j < k; j++) {
      int sign = 1;
      if (mask & (1 << j)) sign = -1;
      assert(arr1[mask] >= 0 && arr2[cmask] >= 0);
      assert(arr1[mask] < 400100 && arr2[cmask] < 400100);
      cur += sign * a[arr1[mask]][j];
      cur -= sign * a[arr2[cmask]][j];
    }
    res = max(res, cur);
  }
  return res;
}
int get_better(int i1, int i2, int msk) {
  int s1 = 0, s2 = 0;
  for (int i = 0; i < k; i++) {
    if (msk & (1 << i))
      s1 -= a[i1][i], s2 -= a[i2][i];
    else
      s1 += a[i1][i], s2 += a[i2][i];
  }
  return s1 > s2 ? i1 : i2;
}
int lll[1 << 5], rr[1 << 5];
int get_max(int l, int r) {
  int res = 0;
  bool rri = false, lli = false;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) {
      res = max(res, calc_best(tree[l], tree[l]));
      if (!lli) {
        for (int j = 0; j < (1 << k); j++) lll[j] = tree[l][j];
        lli = true;
      } else
        for (int j = 0; j < (1 << k); j++)
          lll[j] = get_better(lll[j], tree[l][j], j);
      res = max(res, calc_best(lll, lll));
      l++;
    }
    if (r & 1) {
      --r;
      res = max(res, calc_best(tree[r], tree[r]));
      if (!rri) {
        for (int j = 0; j < (1 << k); j++) rr[j] = tree[r][j];
        rri = true;
      } else
        for (int j = 0; j < (1 << k); j++)
          rr[j] = get_better(rr[j], tree[r][j], j);
      res = max(res, calc_best(rr, rr));
    }
  }
  return max(res, (lli && rri ? calc_best(lll, rr) : 0));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(20);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < k; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (1 << k); j++) tree[n + i][j] = i;
  for (int i = n - 1; i > 0; i--)
    for (int j = 0; j < (1 << k); j++) {
      tree[i][j] = get_better(tree[i << 1][j], tree[i << 1 | 1][j], j);
    }
  int q;
  cin >> q;
  while (q-- > 0) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      cin >> i;
      i--;
      for (int j = 0; j < k; j++) cin >> a[i][j];
      i += n;
      for (i >>= 1; i > 0; i >>= 1)
        for (int j = 0; j < (1 << k); j++) {
          tree[i][j] = get_better(tree[i << 1][j], tree[i << 1 | 1][j], j);
        }
    } else if (t == 2) {
      int l, r;
      cin >> l >> r;
      l--;
      cout << get_max(l, r) << '\n';
    } else
      assert(false);
  }
  return 0;
}
