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 RMINQUtil(int *st, int ss, int se, int qs, int qe, int index) {
  if (qs <= ss && qe >= se) return st[index];
  if (se < qs || ss > qe) return INT_MAX;
  int mid = (ss + se) / 2;
  return min(RMINQUtil(st, ss, mid, qs, qe, 2 * index + 1),
             RMINQUtil(st, mid + 1, se, qs, qe, 2 * index + 2));
}
int RMAXQUtil(int *st, int ss, int se, int qs, int qe, int index) {
  if (qs <= ss && qe >= se) return st[index];
  if (se < qs || ss > qe) return -INT_MAX;
  int mid = (ss + se) / 2;
  return max(RMAXQUtil(st, ss, mid, qs, qe, 2 * index + 1),
             RMAXQUtil(st, mid + 1, se, qs, qe, 2 * index + 2));
}
int RMINQ(int *st, int n, int qs, int qe) {
  return RMINQUtil(st, 0, n - 1, qs, qe, 0);
}
int RMAXQ(int *st, int n, int qs, int qe) {
  return RMAXQUtil(st, 0, n - 1, qs, qe, 0);
}
void updateMINValue(int arr[], int *st, int ss, int se, int index, int value,
                    int node) {
  if (index < ss || index > se) {
    return;
  }
  if (ss == se) {
    arr[index] = value;
    st[node] = value;
  } else {
    int mid = (ss + se) / 2;
    if (index >= ss && index <= mid)
      updateMINValue(arr, st, ss, mid, index, value, 2 * node + 1);
    else
      updateMINValue(arr, st, mid + 1, se, index, value, 2 * node + 2);
    st[node] = min(st[2 * node + 1], st[2 * node + 2]);
  }
  return;
}
void updateMAXValue(int arr[], int *st, int ss, int se, int index, int value,
                    int node) {
  if (index < ss || index > se) {
    return;
  }
  if (ss == se) {
    arr[index] = value;
    st[node] = value;
  } else {
    int mid = (ss + se) / 2;
    if (index >= ss && index <= mid)
      updateMAXValue(arr, st, ss, mid, index, value, 2 * node + 1);
    else
      updateMAXValue(arr, st, mid + 1, se, index, value, 2 * node + 2);
    st[node] = max(st[2 * node + 1], st[2 * node + 2]);
  }
  return;
}
int constructMINSTUtil(int arr[], int ss, int se, int *st, int si) {
  if (ss == se) {
    st[si] = arr[ss];
    return arr[ss];
  }
  int mid = (ss + se) / 2;
  st[si] = min(constructMINSTUtil(arr, ss, mid, st, si * 2 + 1),
               constructMINSTUtil(arr, mid + 1, se, st, si * 2 + 2));
  return st[si];
}
int constructMAXSTUtil(int arr[], int ss, int se, int *st, int si) {
  if (ss == se) {
    st[si] = arr[ss];
    return arr[ss];
  }
  int mid = (ss + se) / 2;
  st[si] = max(constructMAXSTUtil(arr, ss, mid, st, si * 2 + 1),
               constructMAXSTUtil(arr, mid + 1, se, st, si * 2 + 2));
  return st[si];
}
int *constructMINST(int arr[], int n) {
  int x = (int)(ceil(log2(n)));
  int max_size = 2 * (int)pow(2, x) - 1;
  int *st = new int[max_size];
  constructMINSTUtil(arr, 0, n - 1, st, 0);
  return st;
}
int *constructMAXST(int arr[], int n) {
  int x = (int)(ceil(log2(n)));
  int max_size = 2 * (int)pow(2, x) - 1;
  int *st = new int[max_size];
  constructMAXSTUtil(arr, 0, n - 1, st, 0);
  return st;
}
int main() {
  int n, k;
  cin >> n >> k;
  int a[n][k];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      cin >> a[i][j];
    }
  }
  int arr[1 << (k - 1)][n];
  int temp, k1;
  for (int i = 0; i < (1 << (k - 1)); i++) {
    for (int j = 0; j < n; j++) {
      temp = a[j][0];
      k1 = i;
      for (int k2 = 1; k2 < k; k2++) {
        if (k1 & 1)
          temp -= a[j][k2];
        else
          temp += a[j][k2];
        k1 >>= 1;
      }
      arr[i][j] = temp;
    }
  }
  int *st[1 << k];
  for (int i = 0; i < (1 << (k - 1)); i++) {
    st[i] = constructMINST(arr[i], n);
  }
  for (int i = (1 << (k - 1)); i < (1 << k); i++) {
    st[i] = constructMAXST(arr[i - (1 << (k - 1))], n);
  }
  int q;
  cin >> q;
  int t;
  int ind, l, r;
  int b[k];
  int res;
  while (q--) {
    cin >> t;
    if (t == 1) {
      cin >> ind;
      ind -= 1;
      for (int i = 0; i < k; i++) {
        cin >> b[i];
      }
      for (int i = 0; i < (1 << (k - 1)); i++) {
        temp = b[0];
        k1 = i;
        for (int k2 = 1; k2 < k; k2++) {
          if (k1 & 1)
            temp -= b[k2];
          else
            temp += b[k2];
          k1 >>= 1;
        }
        updateMINValue(arr[i], st[i], 0, n - 1, ind, temp, 0);
        updateMAXValue(arr[i], st[i + (1 << (k - 1))], 0, n - 1, ind, temp, 0);
      }
    } else {
      cin >> l >> r;
      l -= 1;
      r -= 1;
      for (int i = 0; i < (1 << (k - 1)); i++) {
        if (i == 0) {
          res = RMAXQ(st[i + (1 << (k - 1))], n, l, r) - RMINQ(st[i], n, l, r);
        } else {
          res = max(res, RMAXQ(st[i + (1 << (k - 1))], n, l, r) -
                             RMINQ(st[i], n, l, r));
        }
      }
      cout << res << "\n";
    }
  }
  return 0;
}
