#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector > a(m+1, vector(m+1)); REP (i, m) REP (j, m) cin >> a[i+1][j+1]; vector > dp(m+1, vector(m+1)); for (int i = 1; i <= m; i++) { for (int j = 1; j <= m; j++) { dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1] + a[i][j]; } } REP (t, n) { int y, x; cin >> y >> x; int ret = 0; for (int y1 = 1; y1 <= y; y1++) { for (int y2 = y; y2 <= m; y2++) { for (int x1 = 1; x1 <= x; x1++) { for (int x2 = x; x2 <= m; x2++) { long long sum = dp[y2][x2] - dp[y2][x1-1] - dp[y1-1][x2] + dp[y1-1][x1-1]; if (sum == 0) ++ret; } } } } cout << ret << endl; } return 0; }