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 long mod = 1e9 + 7;
const double PI = acos(-1);
int n, i, j, k, t;
int q;
vector<int> tree[800009];
int p[200002][5];
int ver[32][5];
int sz;
const int refer = 1e6;
int dist1(int a, int idx) {
  int ans = 0;
  for (int i = 0; i < k; ++i) ans += abs(p[a][i] - ver[idx][i]);
  return ans;
}
int dist2(int a, int b) {
  int ans = 0;
  for (int i = 0; i < k; ++i) {
    ans += abs(p[a][i] - p[b][i]);
  }
  return ans;
}
void combine(vector<int> &a, const vector<int> &b, const vector<int> &c) {
  for (int i = 0; i < sz; ++i) {
    int db = dist1(b[i], i);
    int dc = dist1(c[i], i);
    if (db > dc)
      a[i] = c[i];
    else
      a[i] = b[i];
  }
}
void build(int l, int r, int pos) {
  if (l == r) {
    for (int i = 0; i < sz; ++i) tree[pos].push_back(l);
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, 2 * pos + 1);
  build(mid + 1, r, 2 * pos + 2);
  tree[pos].resize(sz);
  combine(tree[pos], tree[2 * pos + 1], tree[2 * pos + 2]);
}
void update(int l, int r, int pos, int idx) {
  if (l > idx || r < idx || l == r) {
    return;
  }
  int mid = (l + r) / 2;
  update(l, mid, 2 * pos + 1, idx);
  update(mid + 1, r, 2 * pos + 2, idx);
  combine(tree[pos], tree[2 * pos + 1], tree[2 * pos + 2]);
}
vector<int> query(int l, int r, int pos, int ql, int qr) {
  if (l > qr || r < ql) return vector<int>();
  if (l >= ql && r <= qr) return tree[pos];
  int mid = (l + r) / 2;
  vector<int> a = query(l, mid, 2 * pos + 1, ql, qr);
  vector<int> b = query(mid + 1, r, 2 * pos + 2, ql, qr);
  if (a.size() == 0) return b;
  if (b.size() == 0) return a;
  vector<int> ans(sz);
  combine(ans, a, b);
  return ans;
}
void generate() {
  int R = sz;
  int L = sz >> 1;
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < sz; ++j) {
      ver[j][i] = ((j % R) < L ? -1 : 1) * refer;
    }
    L >>= 1;
    R >>= 1;
  }
}
int main() {
  scanf("%d %d", &n, &k);
  sz = 1 << k;
  generate();
  for (i = 0; i < n; ++i) {
    for (j = 0; j < k; ++j) scanf("%d", p[i] + j);
  }
  build(0, n - 1, 0);
  scanf("%d", &q);
  while (q--) {
    int c;
    scanf("%d", &c);
    if (c == 1) {
      int idx;
      scanf("%d", &idx);
      --idx;
      for (i = 0; i < k; ++i) scanf("%d", p[idx] + i);
      update(0, n - 1, 0, idx);
    } else {
      int l, r, ans = 0;
      vector<int> tmp;
      scanf("%d %d", &l, &r);
      tmp = query(0, n - 1, 0, --l, --r);
      for (i = 0; i < sz - 1; ++i) {
        for (j = i + 1; j < sz; ++j) {
          ans = max(ans, dist2(tmp[i], tmp[j]));
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
