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 MOD = 1000000007;
void yes() {
  cout << "Yes"
       << "\n";
}
void no() {
  cout << "No"
       << "\n";
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
struct FAIL {
  FAIL() {
    cout << "CHANGE!!!"
         << "\n";
  }
};
struct Z {
  int value;
  int version;
  int operator<(const Z &other) const { return value != other.value; }
};
template <class T>
class BaseUpdater {
 public:
  virtual T current_update(T current, T value) const {
    return std::numeric_limits<T>::min();
  }
};
template <class T>
class AddUpdater : public BaseUpdater<T> {
 public:
  T current_update(T current, T value) const override {
    return current + value;
  }
};
template <class T>
class AssignUpdater : public BaseUpdater<T> {
 public:
  T current_update(T current, T value) const override { return value; }
};
template <class T>
class BaseCombiner {
 public:
  virtual T combine(T left, T right) const {
    return std::numeric_limits<T>::min();
  }
  virtual T default_value() const { return std::numeric_limits<T>::min(); }
};
template <class T>
class SumCombiner : public BaseCombiner<T> {
 public:
  T combine(T left, T right) const override { return left + right; }
  T default_value() const override { return 0; }
};
template <class T>
class MaxCombiner : public BaseCombiner<T> {
 public:
  T combine(T left, T right) const override { return max(left, right); }
  T default_value() const override { return std::numeric_limits<T>::min(); }
};
template <class T>
class MinCombiner : public BaseCombiner<T> {
 public:
  T combine(T left, T right) const override { return min(left, right); }
  T default_value() const override { return std::numeric_limits<T>::max(); }
};
long long trunc_log(long long x) { return 63 - __builtin_clzll(x); }
template <class T, class Combiner, class Updater>
class SegmentTreeDown {
  Combiner combiner;
  Updater updater;
  int n;
  int maxn = 1000000;
  int start_pos;
  vector<T> t;
  void build(const vector<T> &a) {
    copy(a.begin(), a.end(), t.begin() + start_pos);
    for (int i = maxn - 1; i > 0; --i) {
      t[i] = combiner.combine(t[i << 1], t[i << 1 | 1]);
    }
  }
  T query_impl(int l, int r) {
    T res = combiner.default_value();
    if (l > r) {
      return res;
    }
    ++r;
    for (l += start_pos, r += start_pos; l < r; l >>= 1, r >>= 1) {
      if (l & 1) {
        res = combiner.combine(res, t[l++]);
      }
      if (r & 1) {
        res = combiner.combine(res, t[--r]);
      }
    }
    return res;
  }
  void update_impl(int pos, T value) {
    pos += start_pos;
    t[pos] = updater.current_update(t[pos], value);
    for (; pos > 1; pos >>= 1) {
      t[pos >> 1] = combiner.combine(t[pos], t[pos ^ 1]);
    }
  }

 public:
  SegmentTreeDown() {}
  SegmentTreeDown(int n)
      : n(n),
        maxn((1 << (trunc_log(n - 1) + 1))),
        start_pos(maxn),
        t(2 * maxn, combiner.default_value()) {}
  SegmentTreeDown(const vector<T> &a)
      : n(a.size()), maxn((1 << (trunc_log(n - 1) + 1))), start_pos(maxn) {
    t.resize(2 * maxn, combiner.default_value());
    build(a);
  }
  void update(int pos, T value) { update_impl(pos, value); }
  T query(int l, int r) { return query_impl(l, r); }
  int size() const { return n; }
};
int calc(const vector<int> &value, int mask) {
  int k = value.size();
  int res = 0;
  for (int i = (0); i < (k); ++i) {
    if (mask & (1 << i)) {
      res += value[i];
    } else {
      res -= value[i];
    }
  }
  return res;
}
int main() {
  int n, k;
  cin >> n >> k;
  vector<SegmentTreeDown<int, MinCombiner<int>, AssignUpdater<int>>> tmin;
  tmin.reserve(1 << (k - 1));
  vector<SegmentTreeDown<int, MaxCombiner<int>, AssignUpdater<int>>> tmax;
  tmax.reserve(1 << (k - 1));
  vector<vector<int>> v(n, vector<int>(k));
  for (int __i = 0; __i < (n); ++__i)
    for (int __j = 0; __j < k; ++__j) cin >> v[__i][__j];
  ;
  vector<vector<int>> t(1 << (k - 1), vector<int>(n));
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (1 << (k - 1)); ++j) {
      t[j][i] = calc(v[i], j);
    }
  }
  for (int i = (0); i < (1 << (k - 1)); ++i) {
    tmin.emplace_back(t[i]);
    tmax.emplace_back(t[i]);
  }
  int q;
  cin >> q;
  for (int i = (0); i < (q); ++i) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos;
      cin >> pos;
      --pos;
      vector<int> b(k);
      for (int __i = 0; __i < (k); ++__i) cin >> b[__i];
      ;
      for (int j = (0); j < (1 << (k - 1)); ++j) {
        int value = calc(b, j);
        tmin[j].update(pos, value);
        tmax[j].update(pos, value);
      }
    } else {
      int l, r;
      cin >> l >> r;
      --l, --r;
      int res = 0;
      for (int j = (0); j < (1 << (k - 1)); ++j) {
        res = max(res, tmax[j].query(l, r) - tmin[j].query(l, r));
      }
      cout << res << "\n";
    }
  }
}
