#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; ll sum[150][150]; ll imos[150][150]; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll N, M; scanf("%lld %lld", &N, &M); for (ll i = 0; i < M; i++) { for (ll j = 0; j < M; j++) { scanf("%lld", &sum[i + 1][j + 1]); } } for (ll i = 0; i < M; i++)for (ll j = 0; j < M; j++) sum[i + 1][j + 1] += sum[i + 1][j] + sum[i][j + 1] - sum[i][j]; for (ll i = 0; i < M; i++) { for (ll j = 0; j < M; j++) { for (ll k = i + 1; k <= M; k++) { for (ll l = j + 1; l <= M; l++) { ll s = sum[k][l] - sum[i][l] - sum[k][j] + sum[i][j]; if (s == 0) { imos[i + 1][j + 1]++; imos[i + 1][l + 1]--; imos[k + 1][j + 1]--; imos[k + 1][l + 1]++; } } } } } for (ll i = 1; i <= M; i++) { for (ll j = 1; j < M; j++) { imos[i][j + 1] += imos[i][j]; } } for (ll i = 1; i < M; i++) { for (ll j = 1; j <= M; j++) { imos[i + 1][j] += imos[i][j]; } } for (ll i = 0; i < N; i++) { ll x, y; scanf("%lld %lld", &x, &y); printf("%lld\n", imos[x][y]); } return 0; }