def main lines = STDIN.readlines h, w = lines[0].split.map {|x| x.to_i} s = [] h.times {|i| s << lines[i + 1].chomp} q = lines[h + 1].chomp.to_i q_array = [] q.times {|i| q_array << lines[h + i + 2].split.map {|x| x.to_i - 1}.to_a} q_array.each do |a, b, c, d| result = 0 a.upto(c) do |y| c_count = 0 b.upto(d) do |x| if s[y][x] == "c" c_count += 1 end end w_count = d - b + 1 - c_count result += w_count * (w_count - 1) / 2 * c_count end b.upto(d) do |x| c_count = 0 a.upto(c) do |y| if s[y][x] == "c" c_count += 1 end end w_count = c - a + 1 - c_count result += w_count * (w_count - 1) / 2 * c_count end puts result end end main()