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 = (int)2e5 + 5;
const int M = 5;
struct TreeNode {
  int mn;
  int mx;
  TreeNode() {
    mn = INT_MAX;
    mx = INT_MIN;
  }
};
TreeNode tree[5 * N][32];
int A[N][M];
int n, k;
void build(int node, int start, int end) {
  if (start == end) {
    int sum = 0;
    for (int j = 0; j < (1 << (k - 1)); j++) {
      sum = 0;
      for (int i = 0; i < k; i++) {
        int sign = 1;
        if (i && (j & (1 << (i - 1)))) {
          sign = -1;
        }
        sum += sign * A[start][i];
      }
      tree[node][j].mx = tree[node][j].mn = sum;
    }
  } else {
    int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    for (int j = 0; j < (1 << (k - 1)); j++) {
      tree[node][j].mx = max(tree[2 * node][j].mx, tree[2 * node + 1][j].mx);
      tree[node][j].mn = min(tree[2 * node][j].mn, tree[2 * node + 1][j].mn);
    }
  }
}
void update(int node, int start, int end, int idx, int val) {
  if (start == end) {
    int sum = 0;
    for (int j = 0; j < (1 << (k - 1)); j++) {
      sum = 0;
      for (int i = 0; i < k; i++) {
        int sign = 1;
        if (i && (j & (1 << (i - 1)))) {
          sign = -1;
        }
        sum += sign * A[idx][i];
      }
      tree[node][j].mx = tree[node][j].mn = sum;
    }
  } else {
    int mid = (start + end) / 2;
    if (start <= idx and idx <= mid) {
      update(2 * node, start, mid, idx, val);
    } else {
      update(2 * node + 1, mid + 1, end, idx, val);
    }
    for (int j = 0; j < (1 << (k - 1)); j++) {
      tree[node][j].mx = max(tree[2 * node][j].mx, tree[2 * node + 1][j].mx);
      tree[node][j].mn = min(tree[2 * node][j].mn, tree[2 * node + 1][j].mn);
    }
  }
}
vector<TreeNode> query(int node, int start, int end, int l, int r) {
  if (r < start or end < l) {
    return {};
  }
  if (l <= start and end <= r) {
    vector<TreeNode> ret(1 << (k - 1));
    for (int j = 0; j < (1 << (k - 1)); j++) {
      ret[j] = tree[node][j];
    }
    return ret;
  }
  int mid = (start + end) / 2;
  auto p1 = query(2 * node, start, mid, l, r);
  auto p2 = query(2 * node + 1, mid + 1, end, l, r);
  if (p1.empty()) {
    return p2;
  }
  if (p2.empty()) {
    return p1;
  }
  vector<TreeNode> ret(1 << (k - 1));
  for (int j = 0; j < (1 << (k - 1)); j++) {
    ret[j].mx = max(p1[j].mx, p2[j].mx);
    ret[j].mn = min(p1[j].mn, p2[j].mn);
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      cin >> A[i][j];
    }
  }
  build(1, 1, n);
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int idx;
      cin >> idx;
      for (int i = 0; i < k; i++) {
        cin >> A[idx][i];
      }
      update(1, 1, n, idx, 0);
    } else {
      int l, r;
      cin >> l >> r;
      auto get = query(1, 1, n, l, r);
      int ans = 0;
      for (int j = 0; j < (1 << (k - 1)); j++) {
        ans = max(ans, abs(get[j].mn - get[j].mx));
      }
      cout << ans << endl;
    }
  }
}
