#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define show(x) cout << #x << " = " << (x) << endl; using namespace std; using ll = long long; using pii = pair; ll sum[135][135]; int main(){ int n,m; cin >> n >> m; rep(i,m){ rep(j,m){ cin >> sum[i][j]; } } rep(i,m)rep(j,m)sum[i][j+1] +=sum[i][j]; rep(i,m)rep(j,m)sum[i+1][j] +=sum[i][j]; while(n--){ int x,y; cin >> x >> y; x--,y--; int ans =0; rep(a,x+1)for(int b = x; b < m; b++)rep(c,y+1)for(int d = y; d < m; d++){ ll s = sum[b][d]; if(a>0)s -= sum[a-1][d]; if(c>0)s -= sum[b][c-1]; if(a>0 and c > 0) s+=sum[a-1][c-1]; if(s==0)ans++; } cout << ans << endl; } }