QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#17931. Chocolate Storage Box

Statistics

Coco has a $3 \times 3$ square grid-shaped chocolate container. This container has a blocked center cell with a screen attached to it that displays numbers. The remaining 8 cells can each hold at most one chocolate.

The screen displays up to 4 numbers, where each number represents the size of a connected component of cells containing chocolates. If there are multiple numbers, they are displayed in ascending order. Two cells are considered connected if they share a common side.

Coco wants to make another identical chocolate container to give to Hanbyeol as a gift. Help Coco test the container to ensure there are no bugs.

Input

The first line contains the number of test cases $T$ ($1 \le T \le 100$).

Each test case consists of 4 lines. The first 3 lines describe the state of the chocolate container. O indicates that there is a chocolate in that cell, X indicates there is none, and the center cell is marked as -. The 4th line contains the number of digits displayed on the screen $n$, followed by the list of numbers $a_1, a_2, \cdots, a_n$ in order ($0 \le n \le 4$, $1 \le a_1 \le a_2 \le \cdots \le a_n \le 8$).

Output

For each test case, output 1 if the display on the screen is correct, and 0 otherwise.

Examples

Input 1

6
OOO
O-O
XOO
1 7
XOO
O-O
XXO
2 1 4
OXO
O-X
XXO
3 1 1 2
XOX
O-O
XOX
4 1 1 1 1
XOO
O-O
OOX
1 6
OXX
O-O
XXO
3 1 1 2

Output 1

1
1
1
1
0
0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.