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;
int maxt[(1 << 5)][600005], mint[(1 << 5)][600005];
int a[5][200005];
int n, k;
int compute(int ind, int mask) {
  int ans = 0;
  for (int i = 0; i < k; i++) {
    if (mask & (1 << i)) {
      ans += a[i][ind];
    } else {
      ans -= a[i][ind];
    }
  }
  return ans;
}
void build(int mask, int v, int l, int r) {
  if (l == r) {
    mint[mask][v] = maxt[mask][v] = compute(l, mask);
    return;
  }
  int m = (l + r) / 2;
  build(mask, 2 * v, l, m);
  build(mask, 2 * v + 1, m + 1, r);
  maxt[mask][v] = max(maxt[mask][2 * v], maxt[mask][2 * v + 1]);
  mint[mask][v] = min(mint[mask][2 * v], mint[mask][2 * v + 1]);
}
void update(int mask, int v, int l, int r, int ind) {
  if (l == r) {
    mint[mask][v] = maxt[mask][v] = compute(ind, mask);
    return;
  }
  int m = (l + r) / 2;
  if (ind <= m)
    update(mask, 2 * v, l, m, ind);
  else
    update(mask, 2 * v + 1, m + 1, r, ind);
  maxt[mask][v] = max(maxt[mask][2 * v], maxt[mask][2 * v + 1]);
  mint[mask][v] = min(mint[mask][2 * v], mint[mask][2 * v + 1]);
}
pair<int, int> query(int mask, int v, int s, int e, int l, int r) {
  if (l <= s && e <= r) return make_pair(maxt[mask][v], mint[mask][v]);
  int m = (s + e) / 2;
  if (r <= m) return query(mask, 2 * v, s, m, l, r);
  if (l >= m + 1) return query(mask, 2 * v + 1, m + 1, e, l, r);
  pair<int, int> q1 = query(mask, 2 * v, s, m, l, r);
  pair<int, int> q2 = query(mask, 2 * v + 1, m + 1, e, l, r);
  return make_pair(max(q1.first, q2.first), min(q1.second, q2.second));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      cin >> a[j][i];
    }
  }
  for (int mask = 0; mask < (1 << k); mask++) {
    build(mask, 1, 1, n);
  }
  int q, type, ind, l, r;
  cin >> q;
  while (q--) {
    cin >> type;
    if (type == 1) {
      cin >> ind;
      for (int i = 0; i < k; i++) {
        cin >> a[i][ind];
      }
      for (int mask = 0; mask < (1 << k); mask++) {
        update(mask, 1, 1, n, ind);
      }
    } else {
      cin >> l >> r;
      pair<int, int> tmp = query(0, 1, 1, n, l, r);
      int ans = tmp.first - tmp.second;
      for (int mask = 1; mask < (1 << k); mask++) {
        tmp = query(mask, 1, 1, n, l, r);
        ans = max(ans, tmp.first - tmp.second);
      }
      cout << ans << endl;
    }
  }
}
