| BSUIR Open XIII: Student final |
|---|
| Finished |
Vadim has long dreamed of finding a well-paid job, and then he learned that the airline "Beda" is looking for a web development engineer. However, it is rumored that this company gives very difficult tasks during interviews, so Vadim decided to send his student on a reconnaissance mission.
It turned out that during the interview, candidates are offered to solve a puzzle. On one table of size $$$n_1 \times m_1$$$, there are holes drilled, and on another table of size $$$n_2 \times m_2$$$, there are figures that represent prisms with a special sensor on the bottom.
The candidate's task is to fill each hole with one of the figures lying on the table. The additional complexity is that each hole must be completely filled, meaning it must match the shape of the figure placed in it. The correctness of the candidate's solution is checked automatically using special sensors, so the figures cannot be turned upside down. It is allowed not to use some of the figures.
The student was unable to complete the task on his own, but he managed to take two photographs of the tables from the task. Now Vadim has photographs of the task, but he, like his student, also could not complete the task. Therefore, Vadim began to suspect whether the task can be solved at all.
To verify his hypothesis, he sent you the photographs of the task and asked for your help.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 1\,000$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a pair of numbers $$$n_1$$$ and $$$m_1$$$ ($$$1 \le n_1, m_1 \le 1\,000$$$) — the height and width of the table with holes.
The next $$$n_1$$$ lines consist of $$$m_1$$$ characters "." or "N" and describe the configuration of the first table. A hole is considered to be a connected set of cells containing the symbol "N".
Next, in the test case is a pair of numbers $$$n_2$$$ and $$$m_2$$$ ($$$1 \le n_2, m_2 \le 1\,000$$$) — the height and width of the table with figures.
The next $$$n_2$$$ lines consist of $$$m_2$$$ characters "." or "F" and describe the configuration of the second table. A figure is considered to be a connected set of cells containing the symbol "F".
It is guaranteed that the sum of $$$n_1 \cdot m_1$$$ and the sum of $$$n_2 \cdot m_2$$$ across all test cases does not exceed $$$1\,000$$$. It is also guaranteed that each figure and each hole fit within a $$$7 \times 7$$$ square.
For each test case, output "Yes" on a separate line if the task can be solved, and "No" otherwise. The letters of the words "Yes" and "No" can be output in any case.
33 3N.NN..NN.3 4F.F....F.FFF3 3N.NN..NN.3 4FFF...F.F..F3 1N.N1 1F
Yes No No
| Name |
|---|


