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>
const int INF = 2000000005;
const long long BIG_INF = 2000000000000000005;
const int mod = 1000000007;
const int P = 31;
const long double PI = 3.141592653589793238462643;
using namespace std;
vector<pair<int, int> > dir = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
bool valid(int x, int y, int n, int m) {
  return x >= 0 && y >= 0 && x < n && y < m;
}
mt19937 rng(1999999973);
vector<vector<pair<int, int> > > t;
void update(int v, int tl, int tr, int pos, int val, int st) {
  if (pos < tl || pos > tr) return;
  if (tl == tr) {
    t[v][st] = make_pair(val, val);
    return;
  }
  int tm = (tl + tr) / 2;
  update(v * 2, tl, tm, pos, val, st);
  update(v * 2 + 1, tm + 1, tr, pos, val, st);
  t[v][st] = make_pair(min(t[v * 2][st].first, t[v * 2 + 1][st].first),
                       max(t[v * 2][st].second, t[v * 2 + 1][st].second));
}
pair<int, int> get(int v, int tl, int tr, int l, int r, int st) {
  if (tl >= l && tr <= r) return t[v][st];
  if (tl > r || tr < l) return make_pair(INF, -INF);
  int tm = (tl + tr) / 2;
  pair<int, int> r1 = get(v * 2, tl, tm, l, r, st),
                 r2 = get(v * 2 + 1, tm + 1, tr, l, r, st);
  return make_pair(min(r1.first, r2.first), max(r1.second, r2.second));
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, k;
  cin >> n >> k;
  t.resize(4 * n, vector<pair<int, int> >(1 << k, make_pair(INF, -INF)));
  vector<int> a(k);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) cin >> a[j];
    for (int j = 0; j < (1 << k); j++) {
      int sum = 0;
      for (int y = 0; y < k; y++) {
        sum += a[y] * (((j >> y) & 1) ? 1 : -1);
      }
      update(1, 0, n - 1, i, sum, j);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos;
      cin >> pos;
      pos--;
      for (int i = 0; i < k; i++) cin >> a[i];
      for (int j = 0; j < (1 << k); j++) {
        int sum = 0;
        for (int y = 0; y < k; y++) {
          sum += a[y] * (((j >> y) & 1) ? 1 : -1);
        }
        update(1, 0, n - 1, pos, sum, j);
      }
    } else {
      int l, r;
      cin >> l >> r;
      l--, r--;
      int ans = 0;
      for (int j = 0; j < (1 << k); j++) {
        pair<int, int> res = get(1, 0, n - 1, l, r, j);
        ans = max(ans, res.second - res.first);
      }
      cout << ans << '\n';
    }
  }
  return 0;
}
