#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const double PI = 3.14159265358979323846; const double EPS = 1e-12; const int INF = 1<<25; typedef pair P; typedef long long ll; typedef unsigned long long ull; #define N 502 #define Q 10000 ll h, w; vector s(N), s2(N); ll a[Q], b[Q], c[Q], d[Q]; ll q; ll res[Q]; ll dp[N][N][N]; void rot(){ for(int i = 0; i < q; i++){ int t; t = h-a[i]-1; a[i] = b[i]; b[i] = t; t = h-c[i]-1; c[i] = d[i]; d[i] = t; swap(b[i], d[i]); } for(int i = 0; i < N; i++) s2[i] = ""; for(int i = h-1; i >= 0; i--) for(int j = 0; j < w; j++) s2[j] += s[i][j]; swap(s, s2); swap(h, w); } void solve(){ //memset(dp, 0, sizeof(dp)); for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ dp[i][j][j] = 0; int nc = 0, nw = 0; for(int k = j; k < w; k++){ if(s[i][k]=='c'){ dp[i][j][k+1] = dp[i][j][k]; nc++; } else { dp[i][j][k+1] = dp[i][j][k]+nw; nw += nc; } } } } for(int l = 0; l < q; l++){ for(int i = a[l]; i <= c[l]; i++){ res[l] += dp[i][b[l]][d[l]+1]; } } } int main(){ cin>>h>>w; for(int i = 0; i < h; i++) cin>>s[i]; cin>>q; for(int i = 0; i < q; i++){ cin>>a[i]>>b[i]>>c[i]>>d[i]; a[i]--; b[i]--; c[i]--; d[i]--; } for(int i = 0; i < 4; i++){ /*cerr<