import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); 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 - 1][j] + field[i][j - 1] - field[i - 1][j - 1] + sc.nextInt(); } } int[] xs = new int[n]; int[] ys = new int[n]; for (int i = 0; i < n; i++) { xs[i] = sc.nextInt(); ys[i] = sc.nextInt(); } int[] ans = new int[n]; for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { for (int k = i + 1; k <= m; k++) { for (int l = j + 1; l <= m; l++) { if (field[k][l] - field[i][l] - field[k][j] + field[i][j] == 0) { for (int a = 0; a < n; a++) { if (xs[a] > i && xs[a] <= k && ys[a] > j && ys[a] <= l) { ans[a]++; } } } } } } } StringBuilder sb = new StringBuilder(); for (int x : ans) { sb.append(x).append("\n"); } System.out.print(sb); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }