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;
using ll = long long;
template <typename T>
struct segtree {
  using Type = T;
  using DeltaType = T;
  const T zero;
  const function<T(T, T)> combine;
  const int size;
  vector<T> tree;
  segtree(T zero, const function<T(T, T)>& combine, int size)
      : zero(zero),
        combine(combine),
        size(size + 1),
        tree(2 * (size + 1), zero) {}
  void update(int i, T x) {
    for (tree[i += size] = x; i >>= 1;)
      tree[i] = combine(tree[i << 1], tree[(i << 1) | 1]);
  }
  T query(int a, int b) {
    T ans_l = zero, ans_r = zero;
    for (a += size, b += size + 1; a < b; a >>= 1, b >>= 1) {
      if (a & 1) ans_l = combine(ans_l, tree[a++]);
      if (b & 1) ans_r = combine(tree[--b], ans_r);
    }
    return combine(ans_l, ans_r);
  }
};
template <typename T>
ostream& operator<<(ostream& os, segtree<T>& t) {
  os << "[";
  bool comma = false;
  for (int i = 0; i <= t.size; i++) {
    if (comma)
      os << ", ";
    else
      comma = true;
    os << t.query(i, i);
  }
  os << "]";
  return os;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<segtree<int>> s_min(1 << k,
                             segtree<int>(
                                 numeric_limits<int>::max(),
                                 [](int x, int y) { return min(x, y); }, n));
  vector<segtree<int>> s_max(1 << k,
                             segtree<int>(
                                 numeric_limits<int>::min(),
                                 [](int x, int y) { return max(x, y); }, n));
  auto read_point = [&](int i) {
    vector<int> pt(k);
    for (int j = 0; j < k; j++) {
      cin >> pt[j];
    }
    for (int mask = 0; mask < 1 << k; mask++) {
      int val = 0;
      for (int j = 0; j < k; j++) {
        val += (mask & (1 << j)) ? pt[j] : -pt[j];
      }
      s_min[mask].update(i, val);
      s_max[mask].update(i, val);
    }
  };
  for (int i = 1; i <= n; i++) {
    read_point(i);
  }
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int i;
      cin >> i;
      read_point(i);
    } else {
      int L, R;
      cin >> L >> R;
      int ans = 0;
      for (int mask = 0; mask < 1 << k; mask++) {
        ans = max(ans, abs(s_min[mask].query(L, R) - s_max[mask].query(L, R)));
      }
      cout << ans << endl;
    }
  }
  return 0;
}
