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 = 1e5 + 5, mod = 1e9 + 7, bit = 61;
template <typename T>
class segment {
 public:
  vector<T> st;
  int n;
  segment() {}
  segment(int _n) {
    n = _n;
    st.resize(2 * n);
  }
  T merge(T a, T b) {
    T res;
    res.first = max(a.first, b.first);
    res.second = min(a.second, b.second);
    return res;
  }
  void create() {
    for (int i = n - 1; i > 0; i--) {
      st[i] = merge(st[i << 1], st[(i << 1) | 1]);
    }
  }
  void update(int idx, T val) {
    for (st[idx += n - 1] = val; idx > 1; idx >>= 1) {
      st[idx >> 1] = merge(st[min(idx, idx ^ 1)], st[max(idx, idx ^ 1)]);
    }
  }
  T query(int l, int r) {
    T ans{};
    T ansl{};
    T ansr{};
    ans.first = -2147483647, ans.second = 2147483647;
    ansl.first = -2147483647, ansl.second = 2147483647;
    ansr.first = -2147483647, ansr.second = 2147483647;
    for (l += n - 1, r += n - 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) {
        ansl = merge(ansl, st[l++]);
      }
      if (r & 1) {
        ansr = merge(st[--r], ansr);
      }
    }
    ans = merge(ansl, ansr);
    return ans;
  }
};
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int x = (1ll << k);
    vector<segment<pair<int, int>>> obj(x, segment<pair<int, int>>(n));
    for (int ii = 1; ii <= n; ii++) {
      int a[k];
      for (int j = 0; j <= k - 1; j++) {
        cin >> a[j];
      }
      for (int i = 0; i <= x - 1; i++) {
        int num = 0;
        for (int j = 0; j <= k - 1; j++) {
          if ((i >> j) & 1) {
            num -= a[j];
          } else {
            num += a[j];
          }
        }
        obj[i].st[ii + n - 1].first = num;
        obj[i].st[ii + n - 1].second = num;
      }
    }
    for (int i = 0; i <= x - 1; i++) {
      obj[i].create();
    }
    int q;
    cin >> q;
    while (q--) {
      int tp;
      cin >> tp;
      if (tp == 1) {
        int id;
        cin >> id;
        int a[k];
        for (int i = 0; i <= k - 1; i++) {
          cin >> a[i];
        }
        for (int i = 0; i <= x - 1; i++) {
          int num = 0;
          for (int j = 0; j <= k - 1; j++) {
            if ((i >> j) & 1) {
              num -= a[j];
            } else {
              num += a[j];
            }
          }
          obj[i].update(id, {num, num});
        }
      } else {
        int l, r;
        cin >> l >> r;
        int ans = 0;
        for (int i = 0; i <= x - 1; i++) {
          ans = max(ans, obj[i].query(l, r + 1).first -
                             obj[i].query(l, r + 1).second);
        }
        cout << ans << '\n';
      }
    }
  }
  return 0;
}
