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 inf = 1e9;
struct obj {
  long long int ans;
  vector<long long int> mini;
  vector<long long int> maxi;
  obj() {
    ans = 0;
    mini = vector<long long int>(32, inf);
    maxi = vector<long long int>(32, -inf);
  }
};
int n, k;
int LIM = 2e5 + 10;
obj combine(obj& a, obj& b) {
  obj ret;
  for (int j = 0; j < (1 << k); j++) {
    ret.mini[j] = min(a.mini[j], b.mini[j]);
    ret.maxi[j] = max(a.maxi[j], b.maxi[j]);
    ret.ans = max(ret.ans, ret.maxi[j] - ret.mini[j]);
  }
  return ret;
}
vector<obj> t(2 * LIM);
void build() {
  for (int i = n - 1; i >= 1; i--) {
    t[i] = combine(t[2 * i], t[2 * i + 1]);
  }
}
obj query(int l, int r) {
  obj ret;
  l = l + n - 1;
  r = r + n - 1;
  while (l <= r) {
    if (l % 2 == 1) {
      ret = combine(ret, t[l]);
      l++;
    }
    if (r % 2 == 0) {
      ret = combine(ret, t[r]);
      r--;
    }
    l = l / 2;
    r = r / 2;
  }
  return ret;
}
void update(int i) {
  vector<long long int> b(k + 1);
  for (int j = 0; j < k; j++) cin >> b[j];
  for (int j = 0; j < (1 << k); j++) {
    int temp = 0;
    for (int l = 0; l < k; l++) temp += ((j & (1 << l)) ? b[l] : -b[l]);
    t[i + n - 1].mini[j] = temp;
    t[i + n - 1].maxi[j] = temp;
    t[i + n - 1].ans = 0;
  }
  i = i + n - 1;
  while (i >= 1) {
    i = i / 2;
    t[i] = combine(t[2 * i], t[2 * i + 1]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  vector<vector<long long int> > arr(n + 1, vector<long long int>(k + 1, 0));
  for (long long int i = 1; i <= n; i++) {
    for (long long int j = 0; j < k; j++) cin >> arr[i][j];
    for (long long int j = 0; j < (1 << k); j++) {
      long long int temp = 0;
      for (int l = 0; l < k; l++)
        temp += ((j & (1 << l)) ? arr[i][l] : -arr[i][l]);
      t[i + n - 1].mini[j] = min(t[i + n - 1].mini[j], temp);
      t[i + n - 1].maxi[j] = max(t[i + n - 1].maxi[j], temp);
    }
  }
  build();
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int op;
    cin >> op;
    if (op == 1) {
      int num;
      cin >> num;
      update(num);
    } else {
      int l, r;
      cin >> l >> r;
      cout << query(l, r).ans << endl;
    }
  }
  return 0;
}
