package yukicoder; import java.util.Arrays; import java.util.Scanner; public class Q440 { public static void main(String[] args) { new Q440().run(); } void run() { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); char[][] map = new char[H][W]; for (int i = 0; i < H; ++i) { map[i] = sc.next().toCharArray(); } int Q = sc.nextInt(); int[] a = new int[Q]; int[] b = new int[Q]; int[] c = new int[Q]; int[] d = new int[Q]; for (int i = 0; i < Q; ++i) { b[i] = sc.nextInt() - 1; a[i] = sc.nextInt() - 1; d[i] = sc.nextInt() - 1; c[i] = sc.nextInt() - 1; } long[] ans1 = solver(H, W,Q, map, a, b, c, d); char[][] aaa=new char[H][W]; for(int i=0;i 0 ? WsV[i][j - 1] : 0) + (map[j][i] == 'w' ? 1 : 0); if (j > 0) CWsV[i][j] = CWsV[i][j - 1] + (map[j][i] == 'w' ? (j - WsV[i][j - 1]) : 0); if (j > 1) { CWWsV[i][j] = CWWsV[i][j - 1]; if (map[j][i] == 'w') CWWsV[i][j] += CWsV[i][j - 1]; } } } for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { WsH[i][j] = (j > 0 ? WsH[i][j - 1] : 0) + (map[i][j] == 'w' ? 1 : 0);// ok if (j > 0) CWsH[i][j] = CWsH[i][j - 1] + (map[i][j] == 'w' ? (j - WsH[i][j - 1]) : 0);// ok if (j > 1) { CWWsH[i][j] = CWWsH[i][j - 1]; if (map[i][j] == 'w') CWWsH[i][j] += CWsH[i][j - 1]; } } } long ans[] = new long[Q]; for (int i = 0; i < Q; ++i) { for (int x = a[i]; x <= c[i]; ++x) { ans[i] += CWWsV[x][d[i]] - (b[i] > 0 ? CWWsV[x][b[i] - 1] : 0); ans[i] -= (b[i] - (b[i] > 0 ? WsV[x][b[i] - 1] : 0)) * (WsV[x][d[i]] - (b[i] > 0 ? WsV[x][b[i] - 1] : 0)) * (WsV[x][d[i]] - (b[i] > 0 ? WsV[x][b[i] - 1] : 0) - 1) / 2;// [c][ww] ans[i] -= (b[i] > 0 ? CWsV[x][b[i] - 1] : 0) * (WsV[x][d[i]] - (b[i] > 0 ? WsV[x][b[i] - 1] : 0));// [cw][w] } for (int y = b[i]; y <= d[i]; ++y) { ans[i] += CWWsH[y][c[i]] - (a[i] > 0 ? CWWsH[y][a[i] - 1] : 0); ans[i] -= (a[i] - (a[i] > 0 ? WsH[y][a[i] - 1] : 0)) * (WsH[y][c[i]] - (a[i] > 0 ? WsH[y][a[i] - 1] : 0)) * (WsH[y][c[i]] - (a[i] > 0 ? WsH[y][a[i] - 1] : 0) - 1) / 2; ans[i] -= (a[i] > 0 ? CWsH[y][a[i] - 1] : 0) * (WsH[y][c[i]] - (a[i] > 0 ? WsH[y][a[i] - 1] : 0)); } } return ans; } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }