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 N = 2e5 + 3;
int it_max[32][N * 4], it_min[32][N * 4], a[N];
void load() {}
void update(int Mask, int k, int x, int l, int r, int val) {
  if (l > x || r < x) return;
  if (x == l && x == r) {
    it_max[Mask][k] = it_min[Mask][k] = val;
    return;
  }
  int m = (l + r) >> 1;
  update(Mask, k * 2, x, l, m, val);
  update(Mask, k * 2 + 1, x, m + 1, r, val);
  it_max[Mask][k] = max(it_max[Mask][k * 2], it_max[Mask][k * 2 + 1]);
  it_min[Mask][k] = min(it_min[Mask][k * 2], it_min[Mask][k * 2 + 1]);
  return;
}
int get_max(int Mask, int k, int x, int y, int l, int r) {
  if (x > r || y < l) return -1e9;
  if (l >= x && r <= y) return it_max[Mask][k];
  int m = (l + r) >> 1;
  return max(get_max(Mask, k * 2, x, y, l, m),
             get_max(Mask, k * 2 + 1, x, y, m + 1, r));
}
int get_min(int Mask, int k, int x, int y, int l, int r) {
  if (x > r || y < l) return 1e9;
  if (l >= x && r <= y) return it_min[Mask][k];
  int m = (l + r) >> 1;
  return min(get_min(Mask, k * 2, x, y, l, m),
             get_min(Mask, k * 2 + 1, x, y, m + 1, r));
}
pair<int, int> get(int Mask, int k, int x, int y, int l, int r) {
  if (x > r || y < l) return make_pair(-1e9, 1e9);
  if (l >= x && r <= y) return make_pair(it_max[Mask][k], it_min[Mask][k]);
  int m = (l + r) >> 1;
  pair<int, int> tmp1 = get(Mask, k * 2, x, y, l, m);
  pair<int, int> tmp2 = get(Mask, k * 2 + 1, x, y, m + 1, r);
  return make_pair(max(tmp1.first, tmp2.first), min(tmp1.second, tmp2.second));
}
void trungtt() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < k; ++j) scanf("%d", &a[j]);
    for (int Mask = 0; Mask < (1 << k); ++Mask) {
      int res = 0;
      for (int j = 0; j < Mask; ++j)
        if (Mask & (1 << j))
          res += a[j];
        else
          res -= a[j];
      update(Mask, 1, i, 1, n, res);
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int typ;
    scanf("%d", &typ);
    if (typ == 1) {
      int i;
      scanf("%d", &i);
      for (int j = 0; j < k; ++j) scanf("%d", &a[j]);
      for (int Mask = 0; Mask < (1 << k); ++Mask) {
        int res = 0;
        for (int j = 0; j < Mask; ++j)
          if (Mask & (1 << j))
            res += a[j];
          else
            res -= a[j];
        update(Mask, 1, i, 1, n, res);
      }
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      int ans = 0;
      for (int Mask = 0; Mask < (1 << k); ++Mask) {
        pair<int, int> tmp = get(Mask, 1, l, r, 1, n);
        ans = max(ans, tmp.first - tmp.second);
      }
      printf("%d\n", ans);
    }
  }
}
int main() {
  load();
  trungtt();
  return 0;
}
