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 <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
int a[200135][5];
const int MN = 530000;
struct mb {
  int M, T[MN];
  void init(int sz) {
    for (M = 1; sz + 2 > M; M <<= 1)
      ;
  }
  void init(int sz, int val) {
    for (M = 1; sz + 2 > M; M <<= 1)
      ;
    for (int(i) = 0; (i) < (int)(MN); (i)++) T[i] = val;
  }
  void uptMax(int l, int val) {
    l += M;
    T[l] = val;
    while (l > 1) {
      T[l >> 1] = max(T[l], T[l ^ 1]);
      l >>= 1;
    }
  }
  void uptMin(int l, int val) {
    l += M;
    T[l] = val;
    while (l > 1) {
      T[l >> 1] = min(T[l], T[l ^ 1]);
      l >>= 1;
    }
  }
  int qyMax(int l, int r) {
    int ans = -(1 << 30);
    for (l = l + M - 1, r = r + M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
      if (~l & 1) ans = max(ans, T[l ^ 1]);
      if (r & 1) ans = max(ans, T[r ^ 1]);
    }
    return ans;
  }
  int qyMin(int l, int r) {
    int ans = (1 << 30);
    for (l = l + M - 1, r = r + M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
      if (~l & 1) ans = min(ans, T[l ^ 1]);
      if (r & 1) ans = min(ans, T[r ^ 1]);
    }
    return ans;
  }
} T[32][2];
int gv(int x, int msk) {
  int ans = 0;
  for (int(j) = 0; (j) < (int)(k); (j)++) {
    int c = (msk >> j & 1) ? 1 : -1;
    ans += c * a[x][j];
  }
  return ans;
}
void fmain(int tid) {
  scanf("%d%d", &n, &k);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    for (int(j) = 0; (j) < (int)(k); (j)++) scanf("%d", &a[i][j]);
  }
  for (int(s) = 0; (s) < (int)(1 << k); (s)++) {
    T[s][0].init(n, -(1 << 30));
    T[s][1].init(n, (1 << 30));
  }
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    for (int(s) = 0; (s) < (int)(1 << k); (s)++) {
      int V = gv(i, s);
      T[s][0].uptMax(i, V);
      T[s][1].uptMin(i, V);
    }
  }
  int q;
  scanf("%d", &q);
  for (int(i) = 1; (i) <= (int)(q); (i)++) {
    int t;
    scanf("%d", &t);
    if (t == 2) {
      int l, r;
      scanf("%d%d", &l, &r);
      int ans = 0;
      for (int(s) = 0; (s) < (int)(1 << k); (s)++) {
        int z = T[s][0].qyMax(l, r) - T[s][1].qyMin(l, r);
        maxtt(ans, z);
      }
      printf("%d\n", ans);
    } else {
      int x;
      scanf("%d", &x);
      for (int(j) = 0; (j) < (int)(k); (j)++) scanf("%d", &a[x][j]);
      for (int(s) = 0; (s) < (int)(1 << k); (s)++) {
        int V = gv(x, s);
        T[s][0].uptMax(x, V);
        T[s][1].uptMin(x, V);
      }
    }
  }
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
