#include <bits/stdc++.h>
const int N = 5e3, M = 2e2, L = 20, Inf = 1e9;
int n, m, s[N + 5][M + 5], a[N + 5][M + 5];
struct Matrix {
int ar[M + 5][M + 5];
Matrix operator*(const Matrix &p) const{
Matrix ans, pos;
for (int i = 1; i <= m; ++i) pos.ar[0][i] = 1, pos.ar[i][m + 1] = m;
for (int i = 1; i <= m; ++i)
for (int j = m; j; --j) {
std::pair<int, int> res(Inf, 0);
for (int k = pos.ar[i][j + 1]; k >= pos.ar[i - 1][j]; --k)
res = std::min(res, std::make_pair(ar[i][k] + p.ar[k][j], k));
ans.ar[i][j] = res.first, pos.ar[i][j] = res.second;
}
return ans;
}
};
struct Segment_Tree {
static const int N = ::N / L * 4;
struct Node {
int l, r;
Matrix s;
}ar[N + 5];
#define mid ((l + r) >> 1)
#define ls (k << 1)
#define rs (k << 1 | 1)
void pushup(int k) { ar[k].s = ar[ls].s * ar[rs].s; }
void modify(int k) {
Matrix ans, tmp;
for (int i = 1; i <= m; ++i) for (int j = 1; j <= m; ++j)
ans.ar[i][j] = std::abs(s[ar[k].l][i] - s[ar[k].l][j]) + a[ar[k].l][j];
for (int p = ar[k].l + 1; p <= ar[k].r; ++p) {
for (int i = 1; i <= m; ++i) for (int j = 1; j <= m; ++j)
tmp.ar[i][j] = std::abs(s[p][i] - s[p][j]) + a[p][j];
ans = ans * tmp;
}
ar[k].s = ans;
}
void build(int l = 1, int r = n, int k = 1) {
ar[k].l = l, ar[k].r = r;
if (ar[k].r - ar[k].l + 1 <= L) modify(k);
else build(l, mid, ls), build(mid + 1, r, rs), pushup(k);
}
void update(int x, int k = 1) {
if (x > ar[k].r or x < ar[k].l) return ;
if (ar[k].r - ar[k].l + 1 <= L) return modify(k);
update(x, ls), update(x, rs), pushup(k);
}
int query(int x, int y) { return ar[1].s.ar[x][y]; }
#undef mid
#undef ls
#undef rs
}tr;
int q;
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
std::cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 2; j <= m; ++j) std::cin >> s[i][j], s[i][j] += s[i][j - 1];
for (int i = 1; i < n; ++i) for (int j = 1; j <= m; ++j) std::cin >> a[i][j];
tr.build();
std::cin >> q;
for (int op, x, y, z; q--;) {
std::cin >> op >> x >> y, ++x, ++y;
if (op == 1) {
++y, std::cin >> z, z -= s[x][y] - s[x][y - 1];
for (int i = y; i <= m; ++i) s[x][i] += z;
tr.update(x);
}else if (op == 2) std::cin >> z, a[x][y] = z, tr.update(x);
else std::cout << tr.query(x, y) << "\n";
}
return 0;
}