#include using namespace std; using ll = long long; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b A){ ll L = A.size(); FOR(i, 0, L){ if(i) cout << ' '; cout << A[i]; } cout << endl; } ll A[150][150]; int main(){ cin.tie(0); ios::sync_with_stdio(false); // input ll N, M; cin >> N >> M; ll H = M; ll W = M; FOR(i, 1, M+1){ FOR(j, 1, M+1){ cin >> A[i][j]; } } // 二次元累積和 // 横 FOR(i, 0, H+1){ FOR(j, 0, W+1){ A[i][j+1] += A[i][j]; } } // 縦 FOR(w, 0, W+1){ FOR(h, 0, H+1){ A[h+1][w] += A[h][w]; } } // FOR(y, 0, 5){ // FOR(x, 0, 5){ // cout << setw(2) << A[y][x] << ' '; // } // cout << endl; // } ll Q = N; while(Q--){ ll x, y; cin >> x >> y; ll count = 0; FOR(x0, 1, W+1){ FOR(x1, x0, W+1){ FOR(y0, 1, H+1){ FOR(y1, y0, H+1){ if(x0<=x && x<=x1 && y0<=y && y<=y1){ //ll sum = A[y1][x1] - A[y0-1][x1] - A[y1][x0-1] + A[y0-1][x0-1]; ll sum = A[x1][y1] - A[x0-1][y1] - A[x1][y0-1] + A[x0-1][y0-1]; if(sum==0){ count++; } } } } } } p(count); } return 0; }