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[][] field = new long[m + 1][m + 1]; for (int i = 1; i <= m; i++) { for (int j = 1; j <= m; j++) { field[i][j] = field[i][j - 1] + field[i - 1][j] - field[i - 1][j - 1] + sc.nextInt(); } } 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(); } int[] counts = new int[n]; for (int a = 1; a <= m; a++) { for (int b = 1; b <= m; b++) { for (int c = a; c <= m; c++) { for (int d = b; d <= m; d++) { if (field[c][d] - field[a - 1][d] - field[c][b - 1] + field[a- 1][b - 1] != 0) { continue; } for (int i = 0; i < n; i++) { if (xArr[i] >= a && xArr[i] <= c && yArr[i] >= b && yArr[i] <= d) { counts[i]++; } } } } } } StringBuilder sb = new StringBuilder(); for (int x : counts) { sb.append(x).append("\n"); } System.out.print(sb); } }