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;
int i, j;
int n, k;
vector<vector<pair<int, int>>> segtree(32, vector<pair<int, int>>(600000));
vector<vector<int>> v(5, vector<int>(200005));
vector<string> cand(32);
inline void construct(int index, int l, int r) {
  if (l == r) {
    int segIndex;
    for (segIndex = (0); segIndex < ((1 << k)); segIndex++) {
      int sum = 0;
      int i;
      for (i = (0); i < (k); i++) {
        if (cand[segIndex][i] == '1')
          sum -= v[i][l];
        else
          sum += v[i][l];
      }
      segtree[segIndex][index].first = sum;
      segtree[segIndex][index].second = sum;
    }
    return;
  }
  int mid = ((l + r) >> 1);
  construct(2 * index + 1, l, mid);
  construct(2 * index + 2, mid + 1, r);
  int segIndex;
  for (segIndex = (0); segIndex < ((1 << k)); segIndex++) {
    segtree[segIndex][index].first =
        max(segtree[segIndex][2 * index + 1].first,
            segtree[segIndex][2 * index + 2].first);
    segtree[segIndex][index].second =
        min(segtree[segIndex][2 * index + 1].second,
            segtree[segIndex][2 * index + 2].second);
  }
  return;
}
inline pair<int, int> query(int segIndex, int index, int l, int r, int fl,
                            int fr) {
  if (l >= fl && r <= fr) {
    return segtree[segIndex][index];
  } else if (l > fr || r < fl) {
    return make_pair(-1000000011, 1000000011);
  }
  int mid = ((l + r) >> 1);
  pair<int, int> lh = query(segIndex, 2 * index + 1, l, mid, fl, fr);
  pair<int, int> rh = query(segIndex, 2 * index + 2, mid + 1, r, fl, fr);
  pair<int, int> ans = lh;
  if (rh.first > ans.first) ans.first = rh.first;
  if (rh.second < ans.second) ans.second = rh.second;
  return ans;
}
inline void update(int index, int l, int r, int findex) {
  if (l == r) {
    if (l == findex) {
      int segIndex;
      for (segIndex = (0); segIndex < ((1 << k)); segIndex++) {
        int sum = 0;
        int i;
        for (i = (0); i < (k); i++) {
          if (cand[segIndex][i] == '1')
            sum -= v[i][l];
          else
            sum += v[i][l];
        }
        segtree[segIndex][index].first = sum;
        segtree[segIndex][index].second = sum;
      }
    }
    return;
  }
  int mid = ((l + r) >> 1);
  if (findex <= mid)
    update(2 * index + 1, l, mid, findex);
  else
    update(2 * index + 2, mid + 1, r, findex);
  int segIndex;
  for (segIndex = (0); segIndex < ((1 << k)); segIndex++) {
    segtree[segIndex][index].first =
        max(segtree[segIndex][2 * index + 1].first,
            segtree[segIndex][2 * index + 2].first);
    segtree[segIndex][index].second =
        min(segtree[segIndex][2 * index + 1].second,
            segtree[segIndex][2 * index + 2].second);
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (i = (0); i < (32); i++) {
    int temp = i;
    for (j = (0); j < (5); j++) {
      cand[i] += (temp % 2 + '0');
      temp /= 2;
    }
  }
  cin >> n >> k;
  for (i = (0); i < (n); i++)
    for (j = (0); j < (k); j++) cin >> v[j][i];
  construct(0, 0, n - 1);
  vector<int> ansq;
  int m;
  cin >> m;
  while (m--) {
    int type;
    cin >> type;
    if (type == 1) {
      int i;
      cin >> i;
      i--;
      for (j = (0); j < (k); j++) cin >> v[j][i];
      update(0, 0, n - 1, i);
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      int ans = -1000000011;
      for (j = (0); j < ((1 << k)); j++) {
        pair<int, int> temp = query(j, 0, 0, n - 1, l, r);
        ans = max(ans, temp.first - temp.second);
      }
      ansq.push_back(ans);
    }
  }
  for (i = (0); i < ((int)((ansq).size())); i++) cout << ansq[i] << '\n';
  return 0;
}
