#include <bits/stdc++.h>
using namespace std ;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv)
{
ios::sync_with_stdio(false) ;
int n,m ;
while(cin>>n>>m)
{
int a[n+1][n+1] ;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++) cin>>a[i][j] ;
int x1,y1,x2,y2 ;
while(m--)
{
cin>>x1>>y1>>x2>>y2 ;
int sum=0 ;
for(int i=x1; i<=x2; i++)
for(int j=y1; j<=y2; j++) sum+=a[i][j] ;
cout << sum << "\n" ;
}
}
return 0;
}