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[] xArr = new int[n]; int[] yArr = new int[n]; for (int i = 0; i < n; i++) { xArr[i] = sc.nextInt(); yArr[i] = sc.nextInt(); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { int ans = 0; for (int x1 = 1; x1 <= xArr[i]; x1++) { for (int x2 = xArr[i]; x2 <= m; x2++) { for (int y1 = 1; y1 <= yArr[i]; y1++) { for (int y2 = yArr[i]; y2 <= m; y2++) { if (sums[x2][y2] - sums[x1 - 1][y2] - sums[x2][y1 - 1] + sums[x1 - 1][y1 - 1] == 0) { ans++; } } } } } sb.append(ans).append("\n"); } System.out.print(sb); } }