#include using namespace std; typedef long long int ll; typedef pair P; #define repi(i,a,b) for(ll i=a;i=0;i--) #define MOD 1000000007 //debug #define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<> N >> M; ll A[M][M]; rep(i, M) rep(j, M) cin >> A[i][j]; ll x[N], y[N], ans[N] = {}; rep(i, N) cin >> x[i] >> y[i]; ll sum[M+1][M+1]; rep(i, M+1){ sum[0][i] = 0; sum[i][0] = 0; } rep(i, M) rep(j, M) sum[i+1][j+1] = A[i][j] + sum[i+1][j] + sum[i][j+1] - sum[i][j]; rep(n, N){ // printf("i:%lld j:%lld\n", x[n], y[n]); rep(i1, x[n]) rep(j1, y[n]) repi(i2, x[n], M+1) repi(j2, y[n], M+1){ ll s = sum[i2][j2] - sum[i2][j1] - sum[i1][j2] + sum[i1][j1]; if(s == 0) ans[n]++; // printf("i:%lld j:%lld sum:%lld\n", x[n], y[n], s); } cout << ans[n] << endl; } return 0; }