QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#9621. Polyomino

统计

Given a positive integer $n$ and two strings $a$ and $b$ of length $n$ containing only characters . and #, construct a $7 \times n$ matrix containing only . and # that satisfies the following conditions:

  • The 1st row of the matrix is identical to $a$, and the 7th row is identical to $b$.
  • The shapes formed by # characters connected in four directions are all solid rectangles. Specifically:
    • Two # characters are in the same group if one can reach the other by moving only to adjacent # characters in the four cardinal directions (up, down, left, right). The shape formed by all # characters in the same group must be a solid rectangle.
  • All # characters are connected in eight directions. Specifically:
    • For any two # characters, one can reach the other by moving only to adjacent # characters in the eight directions (up, down, left, right, and the four diagonals).

Output any matrix that satisfies the conditions, or determine that no such matrix exists.

Input

The input is read from standard input. The first line contains a positive integer $T$ ($1 \le T \le 10^4$), representing the number of test cases. Each test case starts with a positive integer $n$ ($2 \le n \le 10^5$), representing the width of the matrix. The next two lines contain two strings $a$ and $b$ of length $n$, consisting only of . and #, representing the 1st and 7th rows of the matrix, respectively. It is guaranteed that both $a$ and $b$ contain at least one #. It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \times 10^5$.

Output

Output to standard output. For each test case, if no such matrix exists, output a single line containing the string No. If such a matrix exists, first output a single line containing the string Yes, followed by 7 lines, each containing a string of length $n$, representing the constructed matrix.

Examples

Input 1

4
4
#..#
.##.
5
##.#.
.#.##
6
######
.####.
27
.######.######.####.#.#####
.####...####..#.......#####

Output 1

Yes
#..#
.##.
.##.
#..#
.##.
.##.
.##.
Yes
##.#.
##.#.
##.#.
..#..
.#.##
.#.##
.#.##
No
Yes
.######.######.####.#.#####
#......#......#....#.#.....
#......#......#....#.#.....
#......#.......####..#.....
#......#......#......#.....
#......#......#......#.....
.####...####..#.......#####

Note

For the first test case, another correct answer is:

#..#
#..#
#..#
.##.
#..#
#..#
.##.

However, the following matrix is not a correct answer because the shape formed by the four-directionally connected # characters at $(1, 1), (2, 1), (2, 2)$ is not a rectangle. The same applies to the group $(4, 1), (4, 2), (5, 1), (6, 1)$.

#..#
##.#
..#.
##.#
#.#.
#..#
.##.

Similarly, the following matrix is not a correct answer because the # character at $(1, 1)$ does not satisfy the eight-direction connectivity condition with the other # characters.

#..#
...#
...#
...#
...#
...#
.##.

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.