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 INF = 1e9;
struct vertex {
  int max;
  int maxI;
  vertex() {
    max = -INF;
    maxI = -1;
  }
  vertex(int x, int ind) {
    max = x;
    maxI = ind;
  }
  friend vertex operator+(vertex &a, vertex &b) {
    if (a.max < b.max) {
      return b;
    }
    return a;
  }
};
const int N = 1 << 18;
struct seg_tree {
  vertex tree[2 * N + 10];
  vertex get(int l, int r) {
    l += N;
    r += N;
    vertex res;
    while (l < r) {
      if (l % 2 == 1) {
        res = res + tree[l];
      }
      if (r % 2 == 0) {
        res = res + tree[r];
      }
      l = (l + 1) / 2;
      r = (r - 1) / 2;
    }
    if (l == r) {
      res = res + tree[l];
    }
    return res;
  }
  void upd(int v, int delta) {
    v += N;
    tree[v] = vertex(delta, v - N);
    v /= 2;
    while (v > 0) {
      tree[v] = tree[v * 2] + tree[v * 2 + 1];
      v /= 2;
    }
  }
};
seg_tree answ[32];
int REV = 31;
int n, k;
void gen(std::vector<int> &a, int &i2, int i, int mask, int sum) {
  if (i == a.size()) {
    answ[mask].upd(i2, sum);
    return;
  }
  gen(a, i2, i + 1, mask, sum + a[i]);
  gen(a, i2, i + 1, mask ^ (1 << i), sum - a[i]);
}
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cin >> n >> k;
  REV = (1 << k) - 1;
  for (int i = 0; i < (n); ++i) {
    std::vector<int> a(k);
    for (int j = 0; j < (k); ++j) {
      std::cin >> a[j];
    }
    gen(a, i, 0, 0, 0);
  }
  int m;
  std::cin >> m;
  for (int i = 0; i < (m); ++i) {
    int type;
    std::cin >> type;
    if (type == 1) {
      int ind;
      std::cin >> ind;
      --ind;
      std::vector<int> a(k);
      for (int j = 0; j < (k); ++j) {
        std::cin >> a[j];
      }
      gen(a, ind, 0, 0, 0);
    } else {
      int l, r;
      std::cin >> l >> r;
      --l;
      --r;
      int answer = 0;
      for (int mask = 0; mask < (16); ++mask) {
        vertex a1 = answ[mask].get(l, r);
        vertex a2 = answ[mask ^ REV].get(l, r);
        if (a1.maxI == a2.maxI) {
        } else {
          answer = std::max(answer, a1.max + a2.max);
        }
      }
      std::cout << answer << '\n';
    }
  }
}
