B - Almost Rectangle

 1. Problem

There is a square field of size n \times nn×n in which two cells are marked. These cells can be in the same row or column.

You are to mark two more cells so that they are the corners of a rectangle with sides parallel to the coordinate axes.

For example, if n=4n=4 and a rectangular field looks like this (there are asterisks in the marked cells):

\begin{matrix} . & . & * & . \\ . & . & . & . \\ * & . & . & . \\ . & . & . & . \\ \end{matrix}..∗.​....​∗...​....​

Then you can mark two more cells as follows

\begin{matrix} * & . & * & . \\ . & . & . & . \\ * & . & * & . \\ . & . & . & . \\ \end{matrix}∗.∗.​....​∗.∗.​....​

If there are several possible solutions, then print any of them.

Input

The first line contains a single integer tt (1 \le t \le 4001≤t≤400). Then tt test cases follow.

The first row of each test case contains a single integer nn (2 \le n \le 4002≤n≤400) — the number of rows and columns in the table.

The following nn lines each contain nn characters '.' or '*' denoting empty and marked cells, respectively.

It is guaranteed that the sums of nn for all test cases do not exceed 400400.

It is guaranteed that there are exactly two asterisks on the field. They can be in the same row/column.

It is guaranteed that the solution exists.

Output

For each test case, output nn rows of nn characters — a field with four asterisks marked corresponding to the statements. If there multiple correct answers, print any of them.

Example

input

6
4
..*.
....
*...
....
2
*.
.*
2
.*
.*
3
*.*
...
...
5
.....
..*..
.....
.*...
.....
4
....
....
*...
*...

output

*.*.
....
*.*.
....
**
**
**
**
*.*
*.*
...
.....
.**..
.....
.**..
.....
....
....
**..
**..

2. Accepted Code

#include<bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;

string s[407];

int main()
{
	int t;
	cin >> t;
	int i, j;

	while (t--)
	{
		int n;
		cin >> n;
		for (i = 0; i < n; i++)
		{
			cin >> s[i];
		}
		int x1, y1, x2, y2, flag = 0;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n; j++)
			{
				if (s[i][j] == '*')
				{
					if (!flag)
					{
					    //记录第一个星号位置
						x1 = i;
						y1 = j;
						flag = 1;
					}
					else
					{
					    //记录第二个星号位置
						x2 = i;
						y2 = j;
					}
				}
			}
		}
		if (x1 == x2)
		{
		    //如果两个星号在同一行
			if (x1 == 0)
			{
				x1 = 1;
				x2 = 1;
			}
			else
			{
				x1 = 0;
				x2 = 0;
			}
		}
		else if (y1 == y2)
		{
		    //如果两个星号在同一列
			if (y1 == 0)
			{
				y1 = 1;
				y2 = 1;
			}
			else
			{
				y1 = 0;
				y2 = 0;
			}
		}
		s[x1][y2] = '*';
		s[x2][y1] = '*';
		for (i = 0; i < n; i++)
		{
			cout << s[i] << '\n';
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/CH_whale/article/details/121442465