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>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int maxn = 262144;
const int maxk = 6;
const int inf = 1e9 + 5;
struct seg_treemax {
  int t[maxn * 2 + 20];
  void update(int v, int tl, int tr, int p, int x) {
    if (tl == tr) {
      t[v] = x;
      return;
    }
    int tm = (tl + tr) >> 1;
    if (p <= tm) {
      update(v << 1, tl, tm, p, x);
    } else {
      update(v << 1 | 1, tm + 1, tr, p, x);
    }
    t[v] = max(t[v << 1], t[v << 1 | 1]);
  }
  int query(int v, int tl, int tr, int l, int r) {
    if (tl > r || tr < l) {
      return -inf;
    }
    if (tl >= l && tr <= r) {
      return t[v];
    }
    int tm = (tl + tr) >> 1;
    return max(query(v << 1, tl, tm, l, r),
               query(v << 1 | 1, tm + 1, tr, l, r));
  }
};
struct seg_treemin {
  int t[maxn * 2 + 20];
  void update(int v, int tl, int tr, int p, int x) {
    if (tl == tr) {
      t[v] = x;
      return;
    }
    int tm = (tl + tr) >> 1;
    if (p <= tm) {
      update(v << 1, tl, tm, p, x);
    } else {
      update(v << 1 | 1, tm + 1, tr, p, x);
    }
    t[v] = min(t[v << 1], t[v << 1 | 1]);
    return;
  }
  int query(int v, int tl, int tr, int l, int r) {
    if (tl > r || tr < l) {
      return inf;
    }
    if (tl >= l && tr <= r) {
      return t[v];
    }
    int tm = (tl + tr) >> 1;
    return min(query(v << 1, tl, tm, l, r),
               query(v << 1 | 1, tm + 1, tr, l, r));
  }
};
seg_treemax tmax[1 << maxk];
seg_treemin tmin[1 << maxk];
vector<int> a[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, k;
  scanf("%d %d", &n, &k);
  int st = 1 << k;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < k; ++j) {
      int x;
      scanf("%d", &x);
      a[i].push_back(x);
    }
  for (int i = 0; i < st; i++) {
    for (int j = 0; j < n; j++) {
      int sum = 0;
      for (int v = 0; v < k; v++) {
        int val = a[j][v];
        if ((i & (1 << v)) > 0) val *= -1;
        sum += val;
      }
      tmax[i].t[j + maxn] = sum;
      tmin[i].t[j + maxn] = sum;
    }
  }
  for (int i = 0; i < st; ++i)
    for (int j = maxn - 1; j > 0; --j) {
      tmax[i].t[j] = max(tmax[i].t[j << 1], tmax[i].t[j << 1 | 1]);
      tmin[i].t[j] = min(tmin[i].t[j << 1], tmin[i].t[j << 1 | 1]);
    }
  int q;
  scanf("%d", &q);
  for (int ii = 0; ii < q; ++ii) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int v;
      scanf("%d", &v);
      v--;
      for (int i = 0; i < k; ++i) scanf("%d", &a[v][i]);
      for (int i = 0; i < st; ++i) {
        int sum = 0;
        for (int j = 0; j < k; j++) {
          int val = a[v][j];
          if ((i & (1 << j)) > 0) val *= -1;
          sum += val;
        }
        tmax[i].update(1, 0, maxn - 1, v, sum);
        tmin[i].update(1, 0, maxn - 1, v, sum);
      }
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      l--;
      r--;
      int ans = -1;
      for (int i = 0; i < st; ++i) {
        int mx = tmax[i].query(1, 0, maxn - 1, l, r);
        int mn = tmin[i].query(1, 0, maxn - 1, l, r);
        ans = max(ans, mx - mn);
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
