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;
const int MAX = 201000;
const long long base = 1e9 + 7;
int nk = 5;
int pk = 32;
int ppp[5] = {1, 2, 4, 8, 16};
struct Node {
  int ind[32];
};
int pos[MAX][5];
Node stree[MAX * 4];
int gstart = 0;
int gend = 1111;
int comp(int mask, int pi1, int pi2) {
  int ta = 0, tb = 0;
  for (int i = 0; i < nk; ++i) {
    if (mask & ppp[i]) {
      ta += pos[pi1][i];
      tb += pos[pi2][i];
    } else {
      ta -= pos[pi1][i];
      tb -= pos[pi2][i];
    }
  }
  return ta - tb;
}
void refresh(Node& n0, Node& n1, Node& n2) {
  for (int i = 0; i < pk; ++i) {
    int c = comp(i, n1.ind[i], n2.ind[i]);
    if (c < 0) {
      n0.ind[i] = n1.ind[i];
    } else {
      n0.ind[i] = n2.ind[i];
    }
  }
}
void refresh(int root, int left, int right) {
  refresh(stree[root], stree[left], stree[right]);
}
void init(int root, int nstart) {
  for (int i = 0; i < pk; ++i) {
    stree[root].ind[i] = nstart;
  }
  return;
}
void buildt(int root, int nstart, int nend) {
  if (nstart == nend) {
    init(root, nstart);
    return;
  }
  int mid = (nstart + nend) / 2;
  int left = root * 2 + 1;
  int right = root * 2 + 2;
  buildt(left, nstart, mid);
  buildt(right, mid + 1, nend);
  refresh(root, left, right);
}
void update(int root, int nstart, int nend, int change) {
  if (change < nstart || change > nend) return;
  if (nstart == nend) {
    init(root, nstart);
    return;
  }
  int mid = (nstart + nend) / 2;
  int left = root * 2 + 1;
  int right = root * 2 + 2;
  update(left, nstart, mid, change);
  update(right, mid + 1, nend, change);
  refresh(root, left, right);
}
Node* query(int root, int nstart, int nend, int b1, int b2) {
  if (b2 < nstart || b1 > nend) return nullptr;
  if (b1 <= nstart && nend <= b2) {
    return new Node(stree[root]);
  }
  int mid = (nstart + nend) / 2;
  int left = root * 2 + 1;
  int right = root * 2 + 2;
  auto r1 = query(left, nstart, mid, b1, b2);
  auto r2 = query(right, mid + 1, nend, b1, b2);
  if (r1 == nullptr) return r2;
  if (r2 == nullptr) return r1;
  Node* tr = new Node;
  refresh(*tr, *r1, *r2);
  delete r1;
  delete r2;
  return tr;
}
void solve() {
  int n;
  cin >> n >> nk;
  pk = 1 << nk;
  gend = n - 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < nk; ++j) {
      cin >> pos[i][j];
    }
  }
  buildt(0, 1, n);
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      int ind;
      cin >> ind;
      for (int j = 0; j < nk; ++j) {
        cin >> pos[ind][j];
      }
      update(0, 1, n, ind);
    } else {
      int l, r;
      cin >> l >> r;
      auto tr = query(0, 1, n, l, r);
      long long result = 0;
      for (int mask = 0; mask < pk / 2; mask++) {
        int op = (pk - 1) ^ mask;
        long long nowd = 0;
        int ind1 = tr->ind[mask];
        int ind2 = tr->ind[op];
        for (int j = 0; j < nk; ++j) {
          nowd += abs(pos[ind1][j] - pos[ind2][j]);
        }
        result = max(result, nowd);
      }
      cout << result << '\n';
      delete tr;
    }
  }
}
int main() {
  const int inId = 0;
  const int outId = 0;
  if (inId > 0) {
    cerr << "redirect stdin to input " << inId << endl;
    string s = "input";
    s += to_string(inId);
    s += ".txt";
    auto r = freopen(s.c_str(), "r", stdin);
    if (r == nullptr) {
      cerr << "invalid input file " << s;
    }
  }
  if (outId > 0) {
    cerr << "redirect stdout to stdout " << outId << endl;
    string s = "stdout";
    s += to_string(outId);
    s += ".txt";
    auto r = freopen(s.c_str(), "w", stdout);
    if (r == nullptr) {
      cerr << "invalid output file " << s;
    }
  }
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  solve();
}
