import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); long[][] sums = new long[m + 1][m + 1]; for (int i = 1; i <= m; i++) { for (int j = 1; j <= m; j++) { sums[i][j] = sc.nextInt() + sums[i - 1][j] + sums[i][j - 1] - sums[i - 1][j - 1]; } } int[] ans = new int[n]; int[] xArr = new int[n]; int[] yArr = new int[n]; for (int i = 0; i < n; i++) { xArr[i] = sc.nextInt(); yArr[i] = sc.nextInt(); } for (int a = 1; a <= m; a++) { for (int b = a; b <= m; b++) { for (int c = 1; c <= m; c++) { for (int d = c; d <=m; d++) { long sum = sums[b][d] - sums[a - 1][d] - sums[b][c - 1] + sums[a - 1][c - 1]; if (sum == 0) { for (int i = 0; i < n; i++) { if (xArr[i] >= a && xArr[i] <= b && yArr[i] >= c && yArr[i] <= d) { ans[i]++; } } } } } } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(ans[i]).append("\n"); } System.out.print(sb); } }