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 k;
struct Monid {
  int maxv, minv;
  Monid() { maxv = -1e9, minv = 1e9; }
  Monid(int ma, int mi) : maxv(ma), minv(mi) {}
  Monid operator*(Monid oth) const {
    return Monid(max(maxv, oth.maxv), min(minv, oth.minv));
  }
  Monid& operator=(Monid oth) {
    maxv = oth.maxv, minv = oth.minv;
    return *this;
  }
  int diff() const { return maxv - minv; }
};
struct Point {
  int a[5];
  int& operator[](int i) { return a[i]; }
  inline int mapPoint(int mask) const {
    int ans = 0;
    for (int i = 0; i < k; ++i) ans += ((mask >> i) & 1) ? a[i] : -a[i];
    return ans;
  }
};
class Seg {
  Seg* ch[2];
  int l, m, r;
  Monid val[32];
  void pull() {
    for (int m = 0; m < (1 << k); ++m) val[m] = ch[0]->val[m] * ch[1]->val[m];
  }

 public:
  Seg(int l, int r, const vector<Point>& A) : l(l), r(r), m(l + r >> 1) {
    if (r - l == 1) {
      for (int m = 0; m < (1 << k); ++m) {
        int v = A[l].mapPoint(m);
        val[m] = Monid(v, v);
      }
    } else {
      ch[0] = new Seg(l, m, A);
      ch[1] = new Seg(m, r, A);
      pull();
    }
  }
  void modify(int p, const Point& a) {
    if (r - l == 1) {
      for (int m = 0; m < (1 << k); ++m) {
        int v = a.mapPoint(m);
        val[m] = Monid(v, v);
      }
    } else {
      if (p < m)
        ch[0]->modify(p, a);
      else
        ch[1]->modify(p, a);
      pull();
    }
  }
  Monid query(int ql, int qr, int j) const {
    if (ql <= l and r <= qr) {
      return val[j];
    } else {
      Monid ans;
      if (ql < m) ans = ans * ch[0]->query(ql, qr, j);
      if (m < qr) ans = ans * ch[1]->query(ql, qr, j);
      return ans;
    }
  }
};
class Solution {
  int n;
  vector<Point> A;

 public:
  void run(istream& in, ostream& out) {
    in >> n >> k;
    A.resize(n);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < k; ++j) {
        in >> A[i][j];
      }
    }
    Seg root(0, n, A);
    int Q, type, idx;
    in >> Q;
    Point a;
    for (int i = 0; i < Q; ++i) {
      in >> type;
      if (type == 1) {
        in >> idx;
        --idx;
        for (int j = 0; j < k; ++j) in >> a[j];
        root.modify(idx, a);
      } else {
        int ans = 0, l, r;
        in >> l >> r;
        --l;
        for (int mask = 0; mask < (1 << k); ++mask) {
          ans = max(ans, root.query(l, r, mask).diff());
        }
        out << ans << '\n';
      }
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  Solution().run(cin, cout);
  return 0;
}
