406749: GYM102535 F Go Go ?

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Go Go ?time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

During the day, your friends know you as the owner of a humble ice cream shop. Little do they know, at night you are none other than the renowned agent Gogo 31!

You have trained for more than 10,000 hours—not as much as the Great Spaitama, but a decent amount nonetheless—and can now easily shoot targets from far away. You can still only shoot in straight lines, unlike your archrival Isli Texon. Your bullet also stops when it hits an enemy or any other obstacle.

Excellent as you are, you take the night as an opportunity to train and improve your shooting skills even further. You turn your ice cream shop and backyard into a shooting range, setting up the targets and obstacles in different configurations.

Your training ground can be viewed as a grid of $$$R$$$ rows and $$$C$$$ columns. When shooting, you can only move along your ice cream shop, which takes up the whole of the bottommost row. The rest of the rows contain either obstacles, targets, or empty space.

For each given configuration, how many targets can you possibly hit?

Input

The first line of the input contains a single integer $$$t$$$, the number of test cases.

Each case starts with integers $$$r$$$ and $$$c$$$, representing your training ground. Then follow $$$r-1$$$ lines with $$$c$$$ characters each. A "#" represents an obstacle, "X" represents a target, and "." is an empty space.

Constraints

$$$0 \le t$$$

$$$2 \le r \le 500$$$

$$$1 \le c \le 500$$$

The sum of ($$$r\times c$$$) across all test cases per file is lower than $$$1000000$$$

Output

For each test case, print a line indicating the number of targets that you could possibly hit.

ExampleInput
2
6 9
XX..X.#.X
..XX..X.X
XX#XX..XX
X.X......
.#.#.#.#.
3 3
###
..X
Output
10
1
Note

The following illustrates the first sample input:

加入题单

上一题 下一题 算法标签: