#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
namespace Xrocks {}
using namespace Xrocks;
namespace Xrocks {
class in {
} user_input;
class out {
} output;
in& operator>>(in& X, int& Y) {
  scanf("%d", &Y);
  return X;
}
in& operator>>(in& X, char* Y) {
  scanf("%s", Y);
  return X;
}
in& operator>>(in& X, float& Y) {
  scanf("%f", &Y);
  return X;
}
in& operator>>(in& X, double& Y) {
  scanf("%lf", &Y);
  return X;
}
in& operator>>(in& X, char& C) {
  scanf("%c", &C);
  return X;
}
in& operator>>(in& X, string& Y) {
  cin >> Y;
  return X;
}
in& operator>>(in& X, long long& Y) {
  scanf("%lld", &Y);
  return X;
}
template <typename T>
in& operator>>(in& X, vector<T>& Y) {
  for (auto& x : Y) user_input >> x;
  return X;
}
template <typename T>
out& operator<<(out& X, const T& Y) {
  cout << Y;
  return X;
}
template <typename T>
out& operator<<(out& X, vector<T>& Y) {
  for (auto& x : Y) output << x << " ";
  return X;
}
out& operator<<(out& X, const int& Y) {
  printf("%d", Y);
  return X;
}
out& operator<<(out& X, const char& C) {
  printf("%c", C);
  return X;
}
out& operator<<(out& X, const string& Y) {
  printf("%s", Y.c_str());
  return X;
}
out& operator<<(out& X, const long long& Y) {
  printf("%lld", Y);
  return X;
}
out& operator<<(out& X, const float& Y) {
  printf("%f", Y);
  return X;
}
out& operator<<(out& X, const double& Y) {
  printf("%lf", Y);
  return X;
}
out& operator<<(out& X, const char Y[]) {
  printf("%s", Y);
  return X;
}
template <typename T>
T max(T A) {
  return A;
}
template <typename T, typename... args>
T max(T A, T B, args... S) {
  return max(A > B ? A : B, S...);
}
template <typename T>
T min(T A) {
  return A;
}
template <typename T, typename... args>
T min(T A, T B, args... S) {
  return min(A < B ? A : B, S...);
}
template <typename T>
void vectorize(int y, vector<T>& A) {
  A.resize(y);
}
template <typename T, typename... args>
void vectorize(int y, vector<T>& A, args&&... S) {
  A.resize(y);
  vectorize(y, S...);
}
long long fast(long long a, long long b, long long pr) {
  if (b == 0) return 1 % pr;
  long long ans = 1 % pr;
  while (b) {
    if (b & 1) ans = (ans * a) % pr;
    b >>= 1;
    a = (a * a) % pr;
  }
  return ans;
}
int readInt() {
  int n = 0;
  int ch = getchar_unlocked();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar_unlocked();
  }
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar_unlocked();
  n = n * sign;
  return n;
}
long long readLong() {
  long long n = 0;
  int ch = getchar_unlocked();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar_unlocked();
  }
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar_unlocked();
  n = n * sign;
  return n;
}
long long readBin() {
  long long n = 0;
  int ch = getchar_unlocked();
  int sign = 1;
  while (ch < '0' || ch > '1') {
    if (ch == '-') sign = -1;
    ch = getchar_unlocked();
  }
  while (ch >= '0' && ch <= '1')
    n = (n << 1) + (ch - '0'), ch = getchar_unlocked();
  return n;
}
long long inv_(long long val,
               long long pr = static_cast<long long>(1000000007)) {
  return fast(val, pr - 2, pr);
}
}  // namespace Xrocks
pair<int, int> operator+(const pair<int, int>& a, const pair<int, int>& b) {
  return {(a.first + b.first) % static_cast<long long>(1000000007),
          (a.second + b.second) % static_cast<long long>(1000000007)};
}
class seg_tree {
  vector<int> tree;
  vector<int> lazy;
  int n;
  inline int get_size(int R) {
    R--;
    int Z = 1;
    while (R) {
      Z <<= 1;
      R >>= 1;
    }
    return Z * 2;
  }

 public:
  void construct(vector<int>& v) {
    tree.resize(get_size(v.size()));
    n = v.size() - 1;
    make_tree(v, 0, v.size() - 1, 1);
  }
  void make_tree(vector<int>& v, int L, int R, int curr) {
    if (L == R) {
      tree[curr] = v[L];
      return;
    }
    int mid = (L + R) / 2;
    make_tree(v, L, mid, 2 * curr);
    make_tree(v, mid + 1, R, 2 * curr + 1);
    tree[curr] = max(tree[2 * curr], tree[2 * curr + 1]);
    return;
  }
  int find_max(int l, int r) { return find_max2(l, r, 0, n, 1); }
  int find_max2(int l, int r, int L, int R, int curr) {
    if (r < L || l > R) return -1e9;
    if (L >= l && R <= r) return tree[curr];
    int c = curr;
    return max(find_max2(l, r, L, (L + R) / 2, 2 * curr),
               find_max2(l, r, (L + R) / 2 + 1, R, 2 * curr + 1));
  }
  void update(int l, int r) { update(l, r, 1, 0, n); }
  void update(int pos, int val, int c, int L, int R) {
    int curr = c;
    if (pos < L || pos > R) return;
    if (L == R) {
      tree[c] = val;
      return;
    }
    update(pos, val, curr << 1, L, (L + R) >> 1);
    update(pos, val, (curr << 1) + 1, ((L + R) >> 1) + 1, R);
    tree[curr] = max(tree[2 * curr], tree[2 * curr + 1]);
    return;
  }
} S[32];
vector<int> A[32];
class solve {
  int n, k;

 public:
  solve() {
    user_input >> n >> k;
    vector<int> v(k);
    for (int i = 0; i < (1 << k); i++) A[i].resize(n);
    for (int i = 0; i < n; i++) {
      user_input >> v;
      for (int j = 0; j < (1 << k); j++) {
        int val = 0;
        for (int z = 0; z < k; z++) {
          if ((j >> z) & 1)
            val += v[z];
          else
            val -= v[z];
        }
        A[j][i] = val;
      }
    }
    for (int i = 0; i < (1 << k); i++) {
      S[i].construct(A[i]);
    }
    int q;
    user_input >> q;
    int z = (1 << k) - 1;
    for (int i = 0; i < q; i++) {
      int t;
      user_input >> t;
      if (t == 1) {
        int pos;
        user_input >> pos >> v;
        --pos;
        for (int j = 0; j < (1 << k); j++) {
          int val = 0;
          for (int z = 0; z < k; z++) {
            if ((j >> z) & 1)
              val += v[z];
            else
              val -= v[z];
          }
          A[j][pos] = val;
          S[j].update(pos, val);
        }
      } else {
        int l, r;
        user_input >> l >> r;
        --l, --r;
        int ans = 0;
        for (int j = 0; j < (1 << k); j++) {
          ans = max(S[j].find_max(l, r) + S[j ^ z].find_max(l, r), ans);
        }
        output << ans << "\n";
      }
    }
  }
};
int32_t main() {
  int t = 1, i = 1;
  if (0 || 0) scanf("%d", &t);
  while (t--) {
    if (0) printf("Case #%d: ", i++);
    new solve;
  }
  output << "\n";
  return 0;
}
