#include <bits/stdc++.h>
using namespace std;
int n, q;
long long m[550][550];
int main()
{
    ios::sync_with_stdio(false);

    srand(time(NULL));

    freopen(".10.in", "w", stdout);
    q = 100000;
    cout<<500<<" "<<q<<endl;

    while( q-- )
    {
        int a, b, c, d, w;
        a = rand()%20 + 1;
        b = rand()%20 + 1;
        c = rand()%20 + 480;
        d = rand()%20 + 480;
        w = rand()%1000000 + 1;
        if( a > c ) swap(a, c);
        if( b > d ) swap(b, d);
        cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<w<<endl;
    }
    freopen(".10.in","r", stdin);
    freopen(".10.out", "w", stdout);
    cin>>n>>q;
    while( q-- )
    {
        int a, b, c, d, w;
        cin>>a>>b>>c>>d>>w;
        m[a][b] += w;
        m[c+1][b] -= w;
        m[a][d+1] -= w;
        m[c+1][d+1] += w;
    }
    for(int i = 1 ; i <= n ; i++ )
        for(int j = 1 ; j <= n ; j++ )
            m[j][i] = m[j-1][i] + m[j][i];
    for(int i = 1 ; i <= n ; i++ )
        for(int j = 1 ; j <= n ; j++ )
            m[i][j] = m[i][j-1] + m[i][j];
    for(int i = 1 ; i <= n ; i++ )
    {
        for(int j = 1 ; j <= n ; j++ )
            cout<<m[i][j]<<" ";
        cout<<endl;
    }
}
