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;
template <class U, class T>
void Max(U &first, T second) {
  if (first < second) first = second;
}
template <class U, class T>
void Min(U &first, T second) {
  if (first > second) first = second;
}
template <class T>
void add(int &a, T b) {
  a = (a + b) % 998244353;
}
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
inline long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
int pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % 998244353;
    a = 1LL * a * a % 998244353;
    b >>= 1;
  }
  return ans;
}
int pow(int a, int b, int c) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % c;
    a = 1LL * a * a % c;
    b >>= 1;
  }
  return ans;
}
int K, t[200010 << 2][1 << 5], mx[200010 << 2], a[200010][5];
void up(int p) {
  mx[p] = max(mx[p << 1], mx[p << 1 | 1]);
  int mask = (1 << K) - 1;
  for (int i = 0; i < (1 << K); i++) {
    Max(mx[p], t[p << 1][i] + t[p << 1 | 1][mask ^ i]);
    t[p][i] = max(t[p << 1][i], t[p << 1 | 1][i]);
  }
}
void build(int p, int l, int r) {
  if (l == r) {
    for (int i = 0; i < (1 << K); i++) {
      for (int j = 0; j < K; j++)
        if (i >> j & 1) {
          t[p][i] += a[l][j];
        } else
          t[p][i] -= a[l][j];
    }
    mx[p] = 0;
    return;
  }
  int m = (l + r) >> 1;
  build(p << 1, l, m);
  build(p << 1 | 1, m + 1, r);
  up(p);
}
void upd(int p, int l, int r, int first) {
  if (l == r) {
    for (int i = 0; i < (1 << K); i++) {
      t[p][i] = 0;
      for (int j = 0; j < K; j++)
        if (i >> j & 1) {
          t[p][i] += a[l][j];
        } else
          t[p][i] -= a[l][j];
    }
    mx[p] = 0;
    return;
  }
  int m = (l + r) >> 1;
  if (first <= m)
    upd(p << 1, l, m, first);
  else
    upd(p << 1 | 1, m + 1, r, first);
  up(p);
}
vector<int> query(int p, int l, int r, int first, int second, int &ans) {
  if (l >= first && r <= second) {
    Max(ans, mx[p]);
    vector<int> v(1 << K);
    for (int i = 0; i < (1 << K); i++) v[i] = t[p][i];
    return v;
  }
  int m = (l + r) >> 1;
  vector<int> v;
  if (second <= m) {
    v = query(p << 1, l, m, first, second, ans);
  } else if (first > m) {
    v = query(p << 1 | 1, m + 1, r, first, second, ans);
  } else {
    vector<int> a = query(p << 1, l, m, first, m, ans);
    vector<int> b = query(p << 1 | 1, m + 1, r, m + 1, second, ans);
    int mask = (1 << K) - 1;
    for (int i = 0; i < (1 << K); i++) Max(ans, a[i] + b[mask ^ i]);
    v.resize(mask + 1);
    for (int i = 0; i < (1 << K); i++) v[i] = max(a[i], b[i]);
  }
  return v;
}
int main() {
  int ca = 0, T, k, i, j, m = 0, n;
  double start = clock();
  scanf("%d%d", &n, &K);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < K; j++) scanf("%d", &a[i][j]);
  }
  build(1, 0, n - 1);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &k);
    if (k == 1) {
      scanf("%d", &i);
      i--;
      for (int j = 0; j < K; j++) scanf("%d", &a[i][j]);
      upd(1, 0, n - 1, i);
    } else {
      scanf("%d%d", &i, &j);
      i--, j--;
      int ans = 0;
      query(1, 0, n - 1, i, j, ans);
      printf("%d\n", ans);
    }
  }
  cerr << (1. * clock() - start) / CLOCKS_PER_SEC << "\n";
}
