import java.util.*; import java.io.*; public class Main { public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int m = Integer.parseInt(first[1]); long[][] field = new long[m + 1][m + 1]; for (int i = 1; i <= m; i++) { String[] line = br.readLine().split(" ", m); for (int j = 1; j <= m; j++) { field[i][j] = field[i][j - 1] + field[i - 1][j] - field[i - 1][j - 1] + Integer.parseInt(line[j - 1]); } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { int count = 0; String[] line = br.readLine().split(" ", 2); int x = Integer.parseInt(line[0]); int y = Integer.parseInt(line[1]); for (int a = 1; a <= x; a++) { for (int b = 1; b <= y; b++) { for (int c = x; c <= m; c++) { for (int d = y; d <= m; d++) { if (field[c][d] - field[a - 1][d] - field[c][b - 1] + field[a- 1][b - 1] == 0) { count++; } } } } } sb.append(count).append("\n"); } System.out.print(sb); } }