// yukicoder: No.755 Zero-Sum Rectangle // 2019.7.31 bal4u #include typedef long long ll; #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { // 整数の入力(負数対応) int n = 0, c = gc(); if (c == '-') { c = gc(); do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return -n; } do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return n; } void out(int n) { // 非負整数の表示(出力) int i; char b[20]; if (!n) pc('0'); else { // if (n < 0) pc('-'), n = -n; i = 0; while (n) b[i++] = n % 10 + '0', n /= 10; while (i--) pc(b[i]); } pc('\n'); } int a[135][135]; ll s[135][135]; int main() { int N, M, r, c, r1, r2, c1, c2, ans; N = in(), M = in(); for (r = 1; r <= M; r++) for (c = 1; c <= M; c++) a[r][c] = in(); for (r = 1; r <= M; r++) for (c = 1; c <= M; c++) { s[r][c] = a[r][c] + s[r][c-1] + s[r-1][c] - s[r-1][c-1]; } while (N--) { r = in(), c = in(), ans = 0; for (r1 = 1; r1 <= r; r1++) for (c1 = 1; c1 <= c; c1++) { for (r2 = r; r2 <= M; r2++) for (c2 = c; c2 <= M; c2++) { if ((s[r2][c2]-s[r1-1][c2]-s[r2][c1-1]+s[r1-1][c1-1]) == 0) ans++; } } out(ans); } return 0; }