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>
int n, k, _pow = 1;
int **a, **arr, **arr1;
struct tree {
  int mask;
  void build(int mask) {
    this->mask = mask;
    while (_pow < n) {
      _pow *= 2;
    }
    arr[mask] = new int[2 * _pow]();
    arr1[mask] = new int[2 * _pow]();
    for (int i = 0; i < n; i++) {
      arr[mask][i + _pow] = i;
      arr1[mask][i + _pow] = 0;
      for (int j = 0; j < k; j++) {
        int si = 1;
        if (mask & (1 << j)) {
          si = -1;
        }
        arr1[mask][i + _pow] += si * a[j][i];
      }
    }
    int po = _pow / 2;
    while (po > 0) {
      for (int i = 0; i < po; i++) {
        if (arr1[mask][2 * i + 2 * po] > arr1[mask][2 * i + 2 * po + 1]) {
          arr1[mask][i + po] = arr1[mask][2 * i + 2 * po];
          arr[mask][i + po] = arr[mask][2 * i + 2 * po];
        } else {
          arr1[mask][i + po] = arr1[mask][2 * i + 2 * po + 1];
          arr[mask][i + po] = arr[mask][2 * i + 2 * po + 1];
        }
      }
      po /= 2;
    }
  }
  void get(int l, int r, int &a1, int &a2) {
    a1 = arr[mask][l];
    a2 = arr1[mask][l];
    while (l <= r) {
      if (l % 2) {
        if (arr1[mask][l] > a2) {
          a2 = arr1[mask][l];
          a1 = arr[mask][l];
        }
        l++;
      }
      if (r % 2 == 0) {
        if (arr1[mask][r] > a2) {
          a2 = arr1[mask][r];
          a1 = arr[mask][r];
        }
        r--;
      }
      l /= 2;
      r /= 2;
    }
  }
  void update(int v) {
    arr1[mask][v] = 0;
    for (int j = 0; j < k; j++) {
      int si = 1;
      if (mask & (1 << j)) {
        si = -1;
      }
      arr1[mask][v] += si * a[j][v - _pow];
    }
    v /= 2;
    if (2 * v + 1 == 2 * _pow) {
      arr1[mask][v] = arr1[mask][2 * v];
      arr[mask][v] = arr[mask][2 * v];
      v /= 2;
    }
    while (v > 0) {
      if (arr1[mask][2 * v] > arr1[mask][2 * v + 1]) {
        arr1[mask][v] = arr1[mask][2 * v];
        arr[mask][v] = arr[mask][2 * v];
      } else {
        arr1[mask][v] = arr1[mask][2 * v + 1];
        arr[mask][v] = arr[mask][2 * v + 1];
      }
      v /= 2;
    }
  }
};
int len(int i, int j) {
  int ans = 0;
  for (int ii = 0; ii < k; ii++) {
    ans += std::abs(a[ii][i] - a[ii][j]);
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  a = new int *[k];
  for (int i = 0; i < k; i++) {
    a[i] = new int[n];
  }
  arr = new int *[1 << k];
  arr1 = new int *[1 << k];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      scanf("%d", &a[j][i]);
    }
  }
  tree tr[1 << k];
  for (int i = 0; i < (1 << k); i++) {
    tr[i].build(i);
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int ind;
      scanf("%d", &ind);
      ind--;
      for (int j = 0; j < k; j++) {
        scanf("%d", &a[j][ind]);
      }
      for (int j = 0; j < (1 << k); j++) {
        tr[j].update(ind + _pow);
      }
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      l--, r--;
      int ans = 0;
      for (int j = 0; j < (1 << (k - 1)); j++) {
        int a1, a2, b1, b2;
        tr[j].get(l + _pow, r + _pow, a1, a2);
        tr[(1 << k) - j - 1].get(l + _pow, r + _pow, b1, b2);
        int qq = len(a1, b1);
        if (qq > ans) {
          ans = qq;
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
