F. Map and Fold
time limit per test
1 second
memory limit per test
960 megabytes
input
standard input
output
standard output
Example
Input
2
3 4
.V.V.M.
M+M+M+M
.M.M.V.
V+M+V+M
.M.M.V.
2 2
.M.
M+M
.M.
Output
YES
NO