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>
#pragma GCC optimize("Ofast")
using namespace std;
const int INF = 1e7;
int tree[4 * 200005][32][2];
int dp[200005][32];
void build(int node, int start, int end, int mask, int m) {
  if (start == end) {
    tree[node][mask][m] = dp[start][mask];
    return;
  }
  int mid = (start + end) / 2;
  build(2 * node, start, mid, mask, m);
  build(2 * node + 1, mid + 1, end, mask, m);
  if (m == 0) {
    tree[node][mask][m] =
        max(tree[2 * node + 1][mask][m], tree[2 * node][mask][m]);
  } else {
    tree[node][mask][m] =
        min(tree[2 * node + 1][mask][m], tree[2 * node][mask][m]);
  }
}
void update(int node, int start, int end, int ind, int upd, int mask, int m) {
  if (start == end && start == ind) {
    dp[ind][mask] = upd;
    tree[node][mask][m] = dp[ind][mask];
  } else {
    int mid = (start + end) / 2;
    if (ind >= start && ind <= mid) {
      update(2 * node, start, mid, ind, upd, mask, m);
    } else if (ind >= mid + 1 && ind <= end) {
      update(2 * node + 1, mid + 1, end, ind, upd, mask, m);
    }
    if (m == 0) {
      tree[node][mask][m] =
          max(tree[2 * node + 1][mask][m], tree[2 * node][mask][m]);
    } else {
      tree[node][mask][m] =
          min(tree[2 * node + 1][mask][m], tree[2 * node][mask][m]);
    }
  }
}
int query(int node, int start, int end, int l, int r, int mask, int m) {
  if (start >= l && end <= r) {
    return tree[node][mask][m];
  }
  if ((end < l) or (start > r)) {
    return INF;
  }
  int mid = (start + end) / 2;
  int q1 = query(2 * node, start, mid, l, r, mask, m);
  int q2 = query(2 * node + 1, mid + 1, end, l, r, mask, m);
  if (q1 == INF) return q2;
  if (q2 == INF) return q1;
  return (m == 0 ? max(q1, q2) : min(q1, q2));
}
void solve() {
  int n, d;
  cin >> n >> d;
  int dd = (1 << d);
  int per[d];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> per[j];
    }
    for (int j = 0; j < dd; j++) {
      for (int k = 0; k < d; k++) {
        if ((j >> k) & 1) {
          dp[i][j] += per[k];
        } else {
          dp[i][j] -= per[k];
        }
      }
    }
  }
  for (int i = 0; i < dd; i++) {
    for (int j = 0; j < 2; j++) {
      build(1, 0, n - 1, i, j);
    }
  }
  int q, ty, l, r;
  cin >> q;
  int upd[dd];
  while (q--) {
    cin >> ty;
    if (ty == 1) {
      int idx;
      cin >> idx;
      idx--;
      for (int i = 0; i < d; i++) {
        cin >> per[i];
      }
      memset(upd, 0, sizeof(upd));
      for (int j = 0; j < dd; j++) {
        for (int k = 0; k < d; k++) {
          if ((j >> k) & 1) {
            upd[j] += per[k];
          } else {
            upd[j] -= per[k];
          }
        }
      }
      for (int i = 0; i < dd; i++) {
        for (int j = 0; j < 2; j++) {
          update(1, 0, n - 1, idx, upd[i], i, j);
        }
      }
    } else {
      cin >> l >> r;
      l--, r--;
      long long ans = 0;
      for (int i = 0; i < dd; i++) {
        int mx = query(1, 0, n - 1, l, r, i, 0);
        int mn = query(1, 0, n - 1, l, r, i, 1);
        ans = max(ans, (long long)(mx - mn));
      }
      cout << ans << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  solve();
  return 0;
}
