#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define endl '\n'
#define int long long
using namespace std;
const int N = 1 << 10;
int tr[N][N], tri[N][N], trj[N][N], trij[N][N];
int n, m;
int Q;
int lowbit(int x)
{
return x & -x;
}
void add(int x, int y, int c)
{
for (int i = x; i <= n; i += lowbit(i))
{
for (int j = y; j <= m; j += lowbit(j))
{
tr[i][j] += c;
tri[i][j] += x * c;
trj[i][j] += y * c;
trij[i][j] += x * y * c;
}
}
}
void update(int x1, int y1, int x2, int y2, int c)
{
add(x1, y1, c);
add(x1, y2 + 1, -c);
add(x2 + 1, y1, -c);
add(x2 + 1, y2 + 1, c);
}
int prefix_sum(int x, int y)
{
int sum = 0;
for (int i = x; i >= 1; i -= lowbit(i))
{
for (int j = y; j >= 1; j -= lowbit(j))
{
sum += (x + 1) * (y + 1) * tr[i][j] - (x + 1) * trj[i][j] - (y + 1) * tri[i][j] + trij[i][j];
}
}
return sum;
}
int sum(int x1, int y1, int x2, int y2)
{
return prefix_sum(x2, y2) - prefix_sum(x1 - 1, y2) - prefix_sum(x2, y1 - 1) + prefix_sum(x1 - 1, y1 - 1);
}
signed main(void)
{
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m;
int op;
while (cin >> op, op)
{
if (op == 1)
{
int x1, y1, x2, y2, val;
cin >> x1 >> y1 >> x2 >> y2 >> val;
update(x1, y1, x2, y2, val);
}
else if (op == 2)
{
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << sum(x1, y1, x2, y2) << endl;
}
else
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cout << sum(i, j, i, j) << ' ';
}
cout << endl;
}
}
}
return 0;
}