There is a square field of size $$$n \times 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=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.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 400$$$). Then $$$t$$$ test cases follow. The first row of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 400$$$) — the number of rows and columns in the table. The following $$$n$$$ lines each contain $$$n$$$ characters '.' or '*' denoting empty and marked cells, respectively. It is guaranteed that the sums of $$$n$$$ for all test cases do not exceed $$$400$$$. 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.

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

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func (in *B) run() {
	t := in.nextInt()
	for i := 0; i < t; i++ {
		n := in.nextInt()
		cm := make([][]byte, n)
		for i := 0; i < n; i++ {
			cm[i] = []byte(in.nextString())
		}
		point := []complex64{complex(0, 0), complex(0, 0)}
		c := 0
		for y := 0; y < n; y++ {
			for x := 0; x < n; x++ {
				if cm[y][x] == '*' {
					point[c] = complex(float32(x), float32(y))
					c++
				}
			}
		}

		if real(point[0]) == real(point[1]) {
			cm[(int(imag(point[0])))%n][(int(real(point[0]))+1)%n] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[1]))+1)%n] = '*'
		} else if imag(point[0]) == imag(point[1]) {
			cm[(int(imag(point[0]))+1)%n][(int(real(point[0])))%n] = '*'
			cm[(int(imag(point[1]))+1)%n][(int(real(point[1])))%n] = '*'
		} else {
			cm[(int(imag(point[0])))%n][(int(real(point[1])))] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[0])))] = '*'

		}
		for y := 0; y < n; y++ {
			Printf("%s\n", string(cm[y]))
		}
	}
}

func main() {
	var F *bufio.Reader
	in, inErr := os.Open("in.txt")
	if inErr == nil {
		F = bufio.NewReader(in)
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(in)
	NewB(F).run()
}

func NewB(r *bufio.Reader) *B {
	return &B{
		in:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

type B struct {
	in        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *B) GetLine() string {
	line, err := in.in.ReadString('\n')
	if err != nil {
		Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}

func (in *B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *B) nextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *B) nextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *B) nextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func (in *B) run(out *bufio.Writer) {
	t := in.nextInt()
	for i := 0; i < t; i++ {
		n := in.nextInt()
		cm := make([][]byte, n)
		for i := 0; i < n; i++ {
			cm[i] = []byte(in.nextString())
		}
		point := []complex64{complex(0, 0), complex(0, 0)}
		c := 0
		for y := 0; y < n; y++ {
			for x := 0; x < n; x++ {
				if cm[y][x] == '*' {
					point[c] = complex(float32(x), float32(y))
					c++
				}
			}
		}

		if real(point[0]) == real(point[1]) {
			cm[(int(imag(point[0])))%n][(int(real(point[0]))+1)%n] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[1]))+1)%n] = '*'
		} else if imag(point[0]) == imag(point[1]) {
			cm[(int(imag(point[0]))+1)%n][(int(real(point[0])))%n] = '*'
			cm[(int(imag(point[1]))+1)%n][(int(real(point[1])))%n] = '*'
		} else {
			cm[(int(imag(point[0])))%n][(int(real(point[1])))] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[0])))] = '*'

		}
		for y := 0; y < n; y++ {
			Printf("%s\n", string(cm[y]))
		}
	}
}

func main() {
	var F *bufio.Reader
	var W *bufio.Writer
	in, inErr := os.Open("in.txt")
	out, outErr := os.Create("out.txt")
	if inErr == nil {
		F = bufio.NewReader(in)
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	created := false
	if outErr == nil {
		created = true
		W = bufio.NewWriter(out)
	} else {
		W = bufio.NewWriter(os.Stdout)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(in)
	defer func(file *os.File) {
		if created {
			_ = W.Flush()
		}
		_ = file.Close()
	}(out)

	NewB(F).run(W)
}

func NewB(r *bufio.Reader) *B {
	return &B{
		in:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

type B struct {
	in        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *B) GetLine() string {
	line, err := in.in.ReadString('\n')
	if err != nil {
		Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}

func (in *B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *B) nextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *B) nextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *B) nextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

package main

import (
	"fmt"
	"strings"
)

var answer string

func main() {
	it := 0
	fmt.Scanf("%d\n", &it)
	for l := 0; l < it; l++ {
		x := 0
		fmt.Scanf("%d\n", &x)
		s := make([][]rune, x)
		for i := 0; i < x; i++ {
			s[i] = make([]rune, x)
		}

		fpx, fpy := -1, -1
		fpxx, fpyy := -1, -1

		for i := 0; i < x; i++ {
			var is string
			// switch i {
			// case 0:
			// 	is = "....."

			// case 1:
			// 	is = "..*.."

			// case 2:
			// 	is = "....."

			// case 3:
			// 	is = ".*..."

			// case 4:
			// 	is = "....."
			// }
			fmt.Scanf("%s\n", &is)
			for k, ss := range is {
				if ss == '*' && fpx == -1 {
					fpy = i
					fpx = k
				} else if ss == '*' && fpx != -1 {
					fpyy = i
					fpxx = k
				}
			}
		}
		print_matrix(fpx, fpy, fpxx, fpyy, x)
	}
	fmt.Println(answer)
}

func print_matrix(x1, y1, x2, y2, x int) {
	// fmt.Println("========")
	if x1 == x2 {
		if x1 > 0 {
			x2--
		} else {
			x2++
		}
	}
	if y1 == y2 {
		if y1 > 0 {
			y2--
		} else {
			y2++
		}
	}
	for i := 0; i < x; i++ {
		if i != y1 && i != y2 {
			// fmt.Println(strings.Repeat(".", x))
			answer += (strings.Repeat(".", x)) + "\n"
		} else {
			str := ""
			for k := 0; k < x; k++ {
				if k == x1 || k == x2 {
					str += "*"
				} else {
					str += "."
				}
			}
			answer += str + "\n"

		}
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var (
		line      string
		char      uint8
		setCount  int
		size      int
		rowsCount int
	)

	firstX := -1
	firstY := -1
	secondX := -1
	secondY := -1
	thirdX := -1
	thirdY := -1
	fourthX := -1
	fourthY := -1

	for scanner.Scan() {
		line = scanner.Text()

		if setCount == 0 {
			setCount = parseInt(line)
			continue
		}

		if size == 0 {
			size = parseInt(line)
			continue
		}

		if rowsCount != size {
			for x := 0; x < size; x++ {
				char = line[x]

				if char == '*' {
					if firstX == -1 {
						firstX = x
						firstY = rowsCount
					} else {
						secondX = x
						secondY = rowsCount
					}
				}
			}

			rowsCount++

			if rowsCount != size {
				continue
			}
		}

		thirdX, thirdY, fourthX, fourthY = findRectangle(firstX, firstY, secondX, secondY, size)

		printMatrix(firstX, firstY, secondX, secondY, thirdX, thirdY, fourthX, fourthY, size)

		// обнуление
		size = 0
		rowsCount = 0
		firstX = -1
		firstY = -1
		secondX = -1
		secondY = -1
		thirdX = -1
		thirdY = -1
		fourthX = -1
		fourthY = -1
	}
}

func parseInt(line string) int {
	i, err := strconv.Atoi(line)
	if err != nil {
		panic(err)
	}

	return i
}

func findRectangle(firstX, firstY, secondX, secondY, size int) (int, int, int, int) {
	var (
		thirdX, thirdY, fourthX, fourthY int
	)

	switch {
	// в плоскости X
	case isPointsInPlaneX(firstX, firstY, secondX, secondY):
		thirdX = firstX
		thirdY = firstY + 1

		// на границе матрицы
		if firstY == (size - 1) {
			thirdY = firstY - 1
		}

		fourthX = secondX
		fourthY = thirdY

	// в плоскости Y
	case isPointsInPlaneY(firstX, firstY, secondX, secondY):
		thirdX = firstX + 1

		// на границе матрицы
		if firstX == (size - 1) {
			thirdX = firstX - 1
		}

		thirdY = firstY
		fourthX = thirdX
		fourthY = secondY

	// по диагонали
	default:
		thirdX = secondX
		thirdY = firstY
		fourthX = firstX
		fourthY = secondY
	}

	return thirdX, thirdY, fourthX, fourthY
}

func isPointsInPlaneX(_, firstY, _, secondY int) bool {
	return firstY == secondY
}

func isPointsInPlaneY(firstX, _, secondX, _ int) bool {
	return firstX == secondX
}

var buf bytes.Buffer

func printMatrix(firstX, firstY, secondX, secondY, thirdX, thirdY, fourthX, fourthY, size int) {
	buf.Reset()

	for y := 0; y < size; y++ {
		for x := 0; x < size; x++ {
			switch {
			case firstX == x && firstY == y,
				secondX == x && secondY == y,
				thirdX == x && thirdY == y,
				fourthX == x && fourthY == y:
				buf.WriteRune('*')
			default:
				buf.WriteRune('.')
			}
		}

		buf.WriteRune('\n')
	}

	fmt.Print(buf.String())
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var (
		line      string
		char      uint8
		setCount  int
		size      int
		rowsCount int
	)

	firstX := -1
	firstY := -1
	secondX := -1
	secondY := -1
	thirdX := -1
	thirdY := -1
	fourthX := -1
	fourthY := -1

	for scanner.Scan() {
		line = scanner.Text()

		if setCount == 0 {
			setCount = parseInt(line)
			continue
		}

		if size == 0 {
			size = parseInt(line)
			continue
		}

		if rowsCount != size {
			for x := 0; x < size; x++ {
				char = line[x]

				if char == '*' {
					if firstX == -1 {
						firstX = x
						firstY = rowsCount
					} else {
						secondX = x
						secondY = rowsCount
					}
				}
			}

			rowsCount++

			if rowsCount != size {
				continue
			}
		}

		thirdX, thirdY, fourthX, fourthY = findRectangle(firstX, firstY, secondX, secondY, size)

		printMatrix(firstX, firstY, secondX, secondY, thirdX, thirdY, fourthX, fourthY, size)

		// обнуление
		size = 0
		rowsCount = 0
		firstX = -1
		firstY = -1
		secondX = -1
		secondY = -1
		thirdX = -1
		thirdY = -1
		fourthX = -1
		fourthY = -1
	}
}

func parseInt(line string) int {
	i, err := strconv.Atoi(line)
	if err != nil {
		panic(err)
	}

	return i
}

func findRectangle(firstX, firstY, secondX, secondY, size int) (int, int, int, int) {
	var (
		thirdX, thirdY, fourthX, fourthY int
	)

	switch {
	// в плоскости X
	case isPointsInPlaneX(firstX, firstY, secondX, secondY):
		thirdX = firstX
		thirdY = firstY + 1

		// на границе матрицы
		if firstY == (size - 1) {
			thirdY = firstY - 1
		}

		fourthX = secondX
		fourthY = thirdY

	// в плоскости Y
	case isPointsInPlaneY(firstX, firstY, secondX, secondY):
		thirdX = firstX + 1

		// на границе матрицы
		if firstX == (size - 1) {
			thirdX = firstX - 1
		}

		thirdY = firstY
		fourthX = thirdX
		fourthY = secondY

	// по диагонали
	default:
		thirdX = secondX
		thirdY = firstY
		fourthX = firstX
		fourthY = secondY
	}

	return thirdX, thirdY, fourthX, fourthY
}

func isPointsInPlaneX(_, firstY, _, secondY int) bool {
	return firstY == secondY
}

func isPointsInPlaneY(firstX, _, secondX, _ int) bool {
	return firstX == secondX
}

func printMatrix(firstX, firstY, secondX, secondY, thirdX, thirdY, fourthX, fourthY, size int) {
	var buf bytes.Buffer
	for y := 0; y < size; y++ {
		for x := 0; x < size; x++ {
			switch {
			case firstX == x && firstY == y,
				secondX == x && secondY == y,
				thirdX == x && thirdY == y,
				fourthX == x && fourthY == y:
				buf.WriteRune('*')
			default:
				buf.WriteRune('.')
			}
		}

		buf.WriteRune('\n')
	}

	fmt.Print(buf.String())
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var (
		line      string
		char      uint8
		setCount  int
		size      int
		rowsCount int
	)

	firstX := -1
	firstY := -1
	secondX := -1
	secondY := -1
	thirdX := -1
	thirdY := -1
	fourthX := -1
	fourthY := -1

	for scanner.Scan() {
		line = scanner.Text()

		if setCount == 0 {
			setCount = parseInt(line)
			continue
		}

		if size == 0 {
			size = parseInt(line)
			continue
		}

		if rowsCount != size {
			for x := 0; x < size; x++ {
				char = line[x]

				if char == '*' {
					if firstX == -1 {
						firstX = x
						firstY = rowsCount
					} else {
						secondX = x
						secondY = rowsCount
					}
				}
			}

			rowsCount++

			if rowsCount != size {
				continue
			}
		}

		thirdX, thirdY, fourthX, fourthY = findRectangle(firstX, firstY, secondX, secondY, size)

		printMatrix(firstX, firstY, secondX, secondY, thirdX, thirdY, fourthX, fourthY, size)

		// обнуление
		size = 0
		rowsCount = 0
		firstX = -1
		firstY = -1
		secondX = -1
		secondY = -1
		thirdX = -1
		thirdY = -1
		fourthX = -1
		fourthY = -1
	}
}

func parseInt(line string) int {
	i, err := strconv.Atoi(line)
	if err != nil {
		panic(err)
	}

	return i
}

func findRectangle(firstX, firstY, secondX, secondY, size int) (int, int, int, int) {
	var (
		thirdX, thirdY, fourthX, fourthY int
	)

	switch {
	// в плоскости X
	case isPointsInPlaneX(firstX, firstY, secondX, secondY):
		thirdX = firstX
		thirdY = firstY + 1

		// на границе матрицы
		if firstY == (size - 1) {
			thirdY = firstY - 1
		}

		fourthX = secondX
		fourthY = thirdY

	// в плоскости Y
	case isPointsInPlaneY(firstX, firstY, secondX, secondY):
		thirdX = firstX + 1

		// на границе матрицы
		if firstX == (size - 1) {
			thirdX = firstX - 1
		}

		thirdY = firstY
		fourthX = thirdX
		fourthY = secondY

	// по диагонали
	default:
		thirdX = secondX
		thirdY = firstY
		fourthX = firstX
		fourthY = secondY
	}

	return thirdX, thirdY, fourthX, fourthY
}

func isPointsInPlaneX(_, firstY, _, secondY int) bool {
	return firstY == secondY
}

func isPointsInPlaneY(firstX, _, secondX, _ int) bool {
	return firstX == secondX
}

func printMatrix(firstX, firstY, secondX, secondY, thirdX, thirdY, fourthX, fourthY, size int) {
	for y := 0; y < size; y++ {
		for x := 0; x < size; x++ {
			switch {
			case firstX == x && firstY == y,
				secondX == x && secondY == y,
				thirdX == x && thirdY == y,
				fourthX == x && fourthY == y:
				fmt.Print("*")
			default:
				fmt.Print(".")
			}
		}

		fmt.Println()
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()

	solve := func() {
		var n int
		Fscan(in, &n)
		a := make([][]byte, n)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		x := make(map[int]int)
		y := make(map[int]int)
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				if a[i][j] == '*' {
					x[i] = 1
					y[j] = 1
				}
			}
		}
		if len(x) == 1 {
			var _x int
			for i, _ := range x {
				_x = i
			}
			x[(_x+1)%n] = 1
		}
		if len(y) == 1 {
			var _y int
			for i, _ := range y {
				_y = i
			}
			y[(_y+1)%n] = 1
		}
		for i, _ := range x {
			for j, _ := range y {
				a[i][j] = '*'
			}
		}
		for i := 0; i < n; i++ {
			Fprintln(out, string(a[i]))
		}

	}

	var T int
	Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var reader *bufio.Reader
var writer *bufio.Writer
var scanner *bufio.Scanner

func init() {
	h, err := os.Hostname()
	if err == nil && h == "turtle" {
		f, err := os.Open("test.txt")
		if err == nil {
			reader = bufio.NewReader(f)
		}
	}
	if reader == nil {
		reader = bufio.NewReader(os.Stdin)
	}
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(reader)
}

func scanf(f string, args ...interface{})  { fmt.Fscanf(reader, f, args...) }
func printf(f string, args ...interface{}) { fmt.Fprintf(writer, f, args...) }
func writeString(s string)                 { writer.WriteString(s) }
func readline() (result string) {
	isPrefix := true
	for isPrefix {
		var bytes []byte = nil
		var err error = nil
		bytes, isPrefix, err = reader.ReadLine()
		if err != nil {
			printf("%s\n", err.Error())
		}
		result += string(bytes)
	}
	return
}
func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}
func if0(a int, b int) int {
	if a == 0 {
		return 1
	}
	return a
}

func search(minX int, maxX int, dx int) (resultX1 int, resultX2 int) {
	if maxX-dx >= 0 {
		resultX1 = maxX - dx
		resultX2 = maxX
	} else {
		resultX1 = minX
		resultX2 = minX + dx
	}
	return
}
func getDots(count int) string {
	if count > 0 {
		return strings.Repeat(".", count)
	}
	return ""
}

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = (n * 10) + int(v-'0')
	}
	return
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	var n int

	scanf("%d\n", &n) // 2≤n≤400

	x1, x2, y1, y2 := -1, -1, -1, -1

	for i := 0; i < n; i++ {
		line := readline()

		if x2 >= 0 {
			continue
		}

		firstStarPos := strings.Index(line, "*")
		if firstStarPos >= 0 {
			if x1 == -1 {
				x1 = i
				y1 = firstStarPos
				if firstStarPos+1 >= len(line) {
					continue
				}
				secondStarPos := strings.Index(line[firstStarPos+1:], "*")
				if secondStarPos >= 0 {
					x2 = i
					y2 = secondStarPos + firstStarPos + 1
				}
			} else {
				x2 = i
				y2 = firstStarPos
			}
		}
	}
	minX := min(x1, x2)
	minY := min(y1, y2)
	maxX := max(x1, x2)
	maxY := max(y1, y2)
	dx := maxX - minX
	dy := maxY - minY

	rx1, rx2 := search(minX, maxX, if0(dx, dy))
	ry1, ry2 := search(minY, maxY, if0(dy, dx))

	allDot := strings.Repeat(".", n) + "\n"

	for i := 0; i < n; i++ {
		if i == rx1 || i == rx2 {
			writeString(
				getDots(ry1) +
					"*" +
					getDots(ry2-ry1-1) +
					"*" +
					getDots(n-ry2-1) +
					"\n",
			)
		} else {
			writeString(allDot)
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

var in *bufio.Reader = bufio.NewReader(os.Stdin)
var out *bufio.Writer = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()

	var t int
	Fscan(in, &t)

	for cases := 0; cases < t; cases++ {
		var n int
		Fscan(in, &n)

		array := make([][]byte, n)
		var idxIAst []int
		var idxJAst []int

		for i := range array {
			Fscan(in, &array[i])

			for j := range array[i] {
				if array[i][j] == '*' {
					idxIAst = append(idxIAst, i)
					idxJAst = append(idxJAst, j)
				}
			}
		}

		if idxIAst[0] == idxIAst[1] {
			if idxIAst[0] > 0 {
				idxIAst = append(idxIAst, idxIAst[0]-1)
				idxJAst = append(idxJAst, idxJAst[0])

				idxIAst = append(idxIAst, idxIAst[0]-1)
				idxJAst = append(idxJAst, idxJAst[1])
			} else {
				idxIAst = append(idxIAst, idxIAst[0]+1)
				idxJAst = append(idxJAst, idxJAst[0])

				idxIAst = append(idxIAst, idxIAst[0]+1)
				idxJAst = append(idxJAst, idxJAst[1])
			}
		} else if idxJAst[0] == idxJAst[1] {
			if idxJAst[0] > 0 {
				idxJAst = append(idxJAst, idxJAst[0]-1)
				idxIAst = append(idxIAst, idxIAst[0])

				idxJAst = append(idxJAst, idxJAst[0]-1)
				idxIAst = append(idxIAst, idxIAst[1])
			} else {
				idxJAst = append(idxJAst, idxJAst[0]+1)
				idxIAst = append(idxIAst, idxIAst[0])

				idxJAst = append(idxJAst, idxJAst[0]+1)
				idxIAst = append(idxIAst, idxIAst[1])
			}
		} else {
			if idxIAst[0] > idxIAst[1] {
				idxIAst = append(idxIAst, idxIAst[1])
				idxIAst = append(idxIAst, idxIAst[0])

				idxJAst = append(idxJAst, idxJAst[0])
				idxJAst = append(idxJAst, idxJAst[1])
			} else {
				idxIAst = append(idxIAst, idxIAst[0])
				idxIAst = append(idxIAst, idxIAst[1])

				idxJAst = append(idxJAst, idxJAst[1])
				idxJAst = append(idxJAst, idxJAst[0])
			}
		}

		for j := 0; j < 4; j++ {
			array[idxIAst[j]][idxJAst[j]] = '*';
		}

		for j := range array {
			Fprintln(out, string(array[j]))
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		var n int
		scanf("%d\n ", &n)

		array := [][]rune{}
		var idxXAst []int
		var idxYAst []int
		for j := 0; j < n; j++ {
			row := make([]rune, n)
			for k, _ := range row {
				if k != n-1 {
					scanf("%c", &row[k])
				} else {
					scanf("%c\n", &row[k])
				}
				if row[k] == '*' {
					idxXAst = append(idxXAst, k)
					idxYAst = append(idxYAst, j)
				}
			}

			array = append(array, row)
		}

		if idxXAst[0] == idxXAst[1] {
			if idxXAst[0] > 0 {
				idxXAst = append(idxXAst, idxXAst[0]-1)
				idxYAst = append(idxYAst, idxYAst[0])

				idxXAst = append(idxXAst, idxXAst[0]-1)
				idxYAst = append(idxYAst, idxYAst[1])
			} else {
				idxXAst = append(idxXAst, idxXAst[0]+1)
				idxYAst = append(idxYAst, idxYAst[0])

				idxXAst = append(idxXAst, idxXAst[0]+1)
				idxYAst = append(idxYAst, idxYAst[1])
			}
		} else if idxYAst[0] == idxYAst[1] {
			if idxYAst[0] > 0 {
				idxYAst = append(idxYAst, idxYAst[0]-1)
				idxXAst = append(idxXAst, idxXAst[0])

				idxYAst = append(idxYAst, idxYAst[0]-1)
				idxXAst = append(idxXAst, idxXAst[1])
			} else {
				idxYAst = append(idxYAst, idxYAst[0]+1)
				idxXAst = append(idxXAst, idxXAst[0])

				idxYAst = append(idxYAst, idxYAst[0]+1)
				idxXAst = append(idxXAst, idxXAst[1])
			}
		} else {
			if idxXAst[0] > idxXAst[1] {
				idxXAst = append(idxXAst, idxXAst[1])
				idxXAst = append(idxXAst, idxXAst[0])

				idxYAst = append(idxYAst, idxYAst[0])
				idxYAst = append(idxYAst, idxYAst[1])
			} else {
				idxXAst = append(idxXAst, idxXAst[0])
				idxXAst = append(idxXAst, idxXAst[1])

				idxYAst = append(idxYAst, idxYAst[1])
				idxYAst = append(idxYAst, idxYAst[0])
			}
		}

		for j := 0; j < 4; j++ {
			array[idxYAst[j]][idxXAst[j]] = '*';
		}

		for j := 0; j < n; j++ {
			for k := 0; k < n; k++ {
				printf("%c", array[j][k])
			}
			printf("\n");
		}
	}
}

package main

import (
	"fmt"
)

type Coord struct {
	i, j int
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x < y {
		return y
	}
	return x
}

func main() {
	var T int
	fmt.Scanln(&T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Scanln(&n)
		var a, b Coord
		a.i = -1
		b.i = -1
		for i := 0; i < n; i++ {
			var line string
			fmt.Scanln(&line)
			for j, c := range(line) {
				if c == '*' {
					if a.i == -1 {
						a.i, a.j = i, j
					} else {
						b.i, b.j = i, j
					}
				}
			}
		}
		var c, d Coord
		if a.i != b.i && a.j != b.j {
			c.i, c.j = a.i, b.j
			d.i, d.j = b.i, a.j
		} else if a.i == b.i {
			if a.i > 0 {
				c.i, c.j = a.i - 1, a.j
				d.i, d.j = a.i - 1, b.j
			} else {
				c.i, c.j = a.i + 1, a.j
				d.i, d.j = a.i + 1, b.j
			}
		} else {
			if a.j > 0 {
				c.j, c.i = a.j - 1, a.i
				d.j, d.i = a.j - 1, b.i
			} else {
				c.j, c.i = a.j + 1, a.i
				d.j, d.i = a.j + 1, b.i
			}
		}

		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				isAsterix := false
				for _, cur := range([]Coord{a, b, c, d}) {
					isAsterix = isAsterix || (cur.i == i && cur.j == j)
				}
				if isAsterix {
					fmt.Print("*")
				} else {
					fmt.Print(".")
				}
			}
			fmt.Println()
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func makeMatrix(n int) [][]string {
	m := make([][]string, n)
	for i, _ := range m {
		m[i] = make([]string, n)
	}
	return m
}

func readMatrix(matrix [][]string) {
	for i := 0; i < len(matrix); i++ {
		var line string
		fmt.Scanf("%s\n", &line)
		matrix[i] = strings.Split(line, "")
	}
}

func solve(matrix [][]string) {
	x1, y1, x2, y2 := -1, -1, -1, -1
	for i, line := range matrix {
		for j, val := range line {
			if val == "*" {
				if x1 == -1 {
					x1 = j
					y1 = i
				} else {
					x2 = j
					y2 = i
				}
			}
		}
	}
	if x2 == x1 {
		if x2 != 0 {
			matrix[y1][x2-1] = "*"
			matrix[y2][x2-1] = "*"
		} else {
			matrix[y1][x2+1] = "*"
			matrix[y2][x2+1] = "*"
		}
	} else if y1 == y2 {
		if y1 != 0 {
			matrix[y1-1][x1] = "*"
			matrix[y2-1][x2] = "*"
		} else {
			matrix[y1+1][x1] = "*"
			matrix[y2+1][x2] = "*"
		}
	} else {
		matrix[y1][x2] = "*"
		matrix[y2][x1] = "*"
	}
}

func print(matrix [][]string) {
	for _, line := range matrix {
		for _, v := range line {
			fmt.Print(v)
		}
		fmt.Print("\n")
	}
}

func main() {
	var nTests int
	fmt.Scanf("%d\n", &nTests)
	for i := 0; i < nTests; i++ {
		var mSize int
		fmt.Scanf("%d\n", &mSize)
		matrix := makeMatrix(mSize)
		readMatrix(matrix)
		solve(matrix)
		print(matrix)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	var line string
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		grid := make([][]int, N)
		type coord struct{ y, x int }
		corners := []coord{}
		for i := 0; i < N; i++ {
			grid[i] = make([]int, N)
			Fscan(in, &line)
			for j := 0; j < N; j++ {
				if line[j] == '.' {
					grid[i][j] = 0
				} else {
					grid[i][j] = 1
					corners = append(corners, coord{i, j})
				}
			}
		}
		y0, x0 := corners[0].y, corners[0].x
		y1, x1 := corners[1].y, corners[1].x

		if y0 == y1 {
			if y0 == 0 {
				grid[1][x0] = 1
				grid[1][x1] = 1
			} else if y0 == N-1 {
				grid[N-2][x0] = 1
				grid[N-2][x1] = 1
			} else {
				grid[y0+1][x0] = 1
				grid[y0+1][x1] = 1
			}
		} else if x0 == x1 {
			if x0 == 0 {
				grid[y0][1] = 1
				grid[y1][1] = 1
			} else if x0 == N-1 {
				grid[y0][N-2] = 1
				grid[y1][N-2] = 1
			} else {
				grid[y0][x0+1] = 1
				grid[y1][x0+1] = 1
			}
		} else {
			grid[y0][x1] = 1
			grid[y1][x0] = 1
		}
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				if grid[i][j] == 0 {
					Fprint(out, ".")
				} else {
					Fprint(out, "*")
				}
			}
			Fprintln(out)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		rec := make([]string, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &rec[i])
		}

		a, b, c, d := solve(&rec)

		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				if (i == a && j == b) || (i == c && d == j) {
					fmt.Print("*")
				} else {
					fmt.Print(string(rec[i][j]))
				}
			}
			fmt.Println()
		}
	}
}

func solve(rec *[]string) (int, int, int, int){

	n :=  len(*rec)
	var fRow, fCol int = -1, -1
	var sRow, sCol int = -1, -1

	for i := 0; i < len(*rec); i++ {
		for j := 0; j < len((*rec)[i]); j++ {
			if (*rec)[i][j] == '*' {
				if fRow == -1 {
					fRow = i
					fCol = j
				} else {
					sRow = i
					sCol = j
				}
			}
		}
	}

	if fRow == sRow && fRow < n - 1 {
		return fRow + 1, fCol, fRow + 1, sCol
	} else if fRow == sRow && fRow == n - 1 {
		return fRow - 1, fCol, fRow - 1, sCol
	} else if fCol == sCol && fCol < n - 1 {
		return fRow, fCol + 1, sRow, fCol + 1
	} else if fCol == sCol && fCol == n - 1 {
		return fRow, fCol - 1, sRow, fCol - 1

	} else {
		return fRow, sCol, sRow, fCol
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
type coords struct{
	row int
	column int
}
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		var star1,star2 coords
		counter:=0
		for j:=0;j<n;j++{
			var x string
			fmt.Fscan(in,&x)
			for k:=0;k<n;k++{
				if string(x[k]) == "*" {
					if counter == 0 {
						star1.row,star1.column = j,k
						counter++
					} else {
						star2.row,star2.column = j,k
					}
				}
			}
		}

		var star3,star4 coords
		if star1.row == star2.row {
			if star1.row == 0 {
				star3.row,star4.row= star1.row+1,star1.row+1
			} else {
				star3.row,star4.row= star1.row-1,star1.row-1
			}
			star3.column,star4.column= star1.column,star2.column

		} else if star1.column == star2.column {
			if star1.column == 0 {
				star3.column,star4.column= star1.column+1,star2.column+1
			} else {
				star3.column,star4.column= star1.column-1,star1.column-1
			}
			star3.row,star4.row= star1.row,star2.row

		} else {
			star3.row,star3.column= star1.row,star2.column
			star4.row,star4.column= star2.row,star1.column
		}
		for j:=0;j<n;j++{
			for k:=0;k<n;k++{
				if (k == star1.column && j == star1.row) || (k == star2.column && j == star2.row) || (k == star3.column && j == star3.row) || (k == star4.column && j == star4.row){
					fmt.Fprintf(out,"*")
				} else {
					fmt.Fprintf(out,".")
				}
			}
			fmt.Fprintln(out,)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader = bufio.NewReader(os.Stdin)

func ri() int {
	var x int
	c, _ := reader.ReadByte()
	for c < '0' || c > '9' {
		c, _ = reader.ReadByte()
	}
	for '0' <= c && c <= '9' {
		x = (x << 3) + (x << 1) + int(c) - '0'
		c, _ = reader.ReadByte()
	}
	return x
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

const MAXN = 2e5 + 5

type Node struct {
	x, y int
}

func Solve() {
	var mp [][]rune
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		mp = append(mp, []rune(s))
	}
	var tmp []Node
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if mp[i][j] == '*' {
				tmp = append(tmp, Node{i, j})
			}
		}
	}
	switch {
	case tmp[0].x == tmp[1].x:
		if tmp[0].x == 0 {
			mp[tmp[0].x+1][tmp[0].y] = '*'
			mp[tmp[0].x+1][tmp[1].y] = '*'
		} else {
			mp[tmp[0].x-1][tmp[0].y] = '*'
			mp[tmp[0].x-1][tmp[1].y] = '*'
		}
	case tmp[0].y == tmp[1].y:
		if tmp[0].y == 0 {
			mp[tmp[0].x][tmp[0].y+1] = '*'
			mp[tmp[1].x][tmp[0].y+1] = '*'
		} else {
			mp[tmp[0].x][tmp[0].y-1] = '*'
			mp[tmp[1].x][tmp[0].y-1] = '*'
		}
	default:
		mp[tmp[0].x][tmp[1].y] = '*'
		mp[tmp[1].x][tmp[0].y] = '*'
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Printf("%c", mp[i][j])
		}
		fmt.Println()
	}
}

func main() {
	var T = 0
	if T == 0 {
		fmt.Scan(&T)
	}
	for t := 1; t <= T; t++ {
		Solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type CF1512B struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1512B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1512B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1512B) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1512B) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1512B) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1512B
Date: 21/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1512/B
Problem: CF1512B
**/
func (in *CF1512B) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		arr := make([][]rune, n)
		pos := make([][]int, 0)
		for i := 0; i < n; i++ {
			str := in.NextString()
			line := make([]rune, n)
			for j := 0; j < n; j++ {
				line[j] = rune(str[j])
				if line[j] == '*' {
					pos = append(pos, []int{i, j})
				}
			}
			arr[i] = line
		}

		x1, y1 := pos[0][0], pos[0][1]
		x2, y2 := pos[1][0], pos[1][1]

		if x1 == x2 {
			if x1 == 0 {
				arr[x1+1][y1] = '*'
				arr[x2+1][y2] = '*'
			} else {
				arr[x1-1][y1] = '*'
				arr[x2-1][y2] = '*'
			}
		} else if y1 == y2 {
			if y1 == 0 {
				arr[x1][y1+1] = '*'
				arr[x2][y2+1] = '*'
			} else {
				arr[x1][y1-1] = '*'
				arr[x2][y2-1] = '*'
			}
		} else {
			arr[x1][y2] = '*'
			arr[x2][y1] = '*'
		}

		var sb strings.Builder

		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				sb.WriteRune(arr[i][j])
			}
			sb.WriteString("\n")
		}
		fmt.Print(sb.String())
	}
}

func NewCF1512B(r *bufio.Reader) *CF1512B {
	return &CF1512B{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1512B(bufio.NewReader(os.Stdin)).Run()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int, m [][]byte) {
	var (
		x, y [2]int
		k    int
	)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if m[i][j] == '*' {
				x[k] = i
				y[k] = j
				k++
			}
		}
	}
	if x[0] != x[1] && y[0] != y[1] {
		y[0], y[1] = y[1], y[0]
	} else if x[0] == x[1] {
		if x[0] > 0 {
			x[0] = 0
			x[1] = 0
		} else {
			x[0] = 1
			x[1] = 1
		}
	} else {
		if y[0] > 0 {
			y[0] = 0
			y[1] = 0
		} else {
			y[0] = 1
			y[1] = 1
		}
	}
	m[x[0]][y[0]] = '*'
	m[x[1]][y[1]] = '*'
	for _, v := range m {
		fmt.Printf("%s\n", v)
	}
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		m := make([][]byte, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &m[i])
		}
		solve(n, m)
	}
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		field := make([][]rune, n)
		minR, maxR, minC, maxC := n-1, 0, n-1, 0

		for r := 0; r < n; r++ {
			field[r] = []rune(ScanString())

			for c := 0; c < n; c++ {
				if field[r][c] == '*' {
					if r < minR {
						minR = r
					}

					if r > maxR {
						maxR = r
					}

					if c < minC {
						minC = c
					}

					if c > maxC {
						maxC = c
					}
				}
			}
		}

		if minR == maxR {
			if minR > 0 {
				minR--
			} else {
				maxR++
			}
		}

		if minC == maxC {
			if minC > 0 {
				minC--
			} else {
				maxC++
			}
		}

		field[minR][minC] = '*'
		field[minR][maxC] = '*'
		field[maxR][minC] = '*'
		field[maxR][maxC] = '*'

		for r := 0; r < n; r++ {
			fmt.Println(string(field[r]))
		}
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
	"math"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		fmt.Fscan(in, &n)
		v := make([][]rune, n)
		mnR, mnC, mxR, mxC := n,n,0,0
		for i := range v {
			v[i] = make([]rune, n + 1)
			var s string
			fmt.Fscan(in, &s)
			v[i] = []rune(s)
			for j, c := range v[i] {
				if c == '*' {
					mnR = int(math.Min(float64(mnR), float64(i)))
					mnC = int(math.Min(float64(mnC), float64(j)))
					mxR = int(math.Max(float64(mxR), float64(i)))
					mxC = int(math.Max(float64(mxC), float64(j)))
				}
			}
		}
		if mnR == mxR {
			mxR = (mxR+1)%n
		}
		if mnC == mxC {
			mxC = (mxC+1)%n
		}
		v[mnR][mnC] = '*'
		v[mnR][mxC] = '*'
		v[mxR][mnC] = '*'
		v[mxR][mxC] = '*'
		for _, s := range v {
			fmt.Println(string(s))
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(input, &n)

		array := make([]string, n)
		Rows := make([]int, 0)
		Columns := make([]int, 0)
		for i := 0; i < n; i++ {
			BBB := make([]byte, 0)
			fmt.Fscan(input, &BBB)
			for k := 0; k < n; k++ {
				if string(BBB[k]) == "*" {
					Rows = append(Rows, i)
					Columns = append(Columns, k)
				}
			}
			array[i] = string(BBB)
		}
		if Rows[0] == Rows[1] {
			if Rows[0] < n-1 {
				array[n-1] = array[n-1][:Columns[0]] + "*" + array[n-1][Columns[0]+1:Columns[1]] + "*" + array[n-1][Columns[1]+1:]
			} else {
				array[0] = array[0][:Columns[0]] + "*" + array[0][Columns[0]+1:Columns[1]] + "*" + array[0][Columns[1]+1:]

			}
		} else {
			if Columns[0] == Columns[1] {
				if Columns[0] < n-1 {
					array[Rows[0]] = array[Rows[0]][:n-1] + "*"
					array[Rows[1]] = array[Rows[0]][:n-1] + "*"

				} else {
					array[Rows[0]] = "*" + array[Rows[0]][1:]
					array[Rows[1]] = "*" + array[Rows[0]][1:]
				}
			} else {
				array[Rows[0]] = array[Rows[0]][:Columns[1]] + "*" + array[Rows[0]][Columns[1]+1:]
				array[Rows[1]] = array[Rows[1]][:Columns[0]] + "*" + array[Rows[1]][Columns[0]+1:]
			}
		}
		for i := 0; i < n; i++ {
			fmt.Println(array[i])
		}

	}

}

package main

import "fmt"

func solve() {
	var n int
	fmt.Scan(&n)
	in := make([][]byte, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&in[i])
	}
	first_i := -1
	first_j := -1
	second_i := -1
	second_j := -1
	for i := 0; i < n; i++ {
		for id, elem := range in[i] {
			if elem == '*' && first_i == -1 {
				first_i = i
				first_j = id
			} else if elem == '*' && second_i == -1 {
				second_i = i
				second_j = id
			}
		}
	}
	if second_j == first_j {
		if second_j < n-1 {
			in[first_i][first_j+1] = '*'
			in[second_i][second_j+1] = '*'
		} else {
			in[first_i][first_j-1] = '*'
			in[second_i][second_j-1] = '*'
		}
	} else if second_i == first_i {
		if second_i < n-1 {
			in[first_i+1][first_j] = '*'
			in[second_i+1][second_j] = '*'
		} else {
			in[first_i-1][first_j] = '*'
			in[second_i-1][second_j] = '*'
		}
	} else {
		in[first_i][second_j] = '*'
		in[second_i][first_j] = '*'
	}
	ans := ""
	for i := range in {
		for j := range in[i] {
			ans += string(in[i][j])
			if j == n-1 {
				ans += "\n"
			}
		}
	}
	fmt.Print(ans)

}

func main() {
	var x int
	fmt.Scan(&x)
	for i := 0; i < x; i++ {
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}
func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}
func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.nextInt()
		grid := make([][]byte, N)
		for i := 0; i < N; i++ {
			grid[i] = []byte(sc.next())
		}

		minr := 500
		maxr := 0
		minc := 500
		maxc := 0
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				if grid[i][j] == '*' {
					minr = min(minr, i)
					maxr = max(maxr, i)
					minc = min(minc, j)
					maxc = max(maxc, j)
				}
			}
		}
		height := max(1, maxr-minr)
		width := max(1, maxc-minc)

		if maxr-height >= 0 {
			minr = maxr - height
		} else {
			maxr = maxr + height
		}
		if maxc-width >= 0 {
			minc = maxc - width
		} else {
			maxc = maxc + width
		}
		grid[minr][minc] = '*'
		grid[minr][maxc] = '*'
		grid[maxr][minc] = '*'
		grid[maxr][maxc] = '*'

		for i := 0; i < N; i++ {
			fmt.Fprintln(wr, string(grid[i]))
		}
	}

}

package main

import (
	"bufio"
	"bytes"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var n, maxr, maxc int
		Fscan(in, &n)
		a := make([][]byte, n)
		minr := -1
		minc := int(1e9)
		for i := range a {
			Fscan(in, &a[i])
			l, r := bytes.Index(a[i], []byte{'*'}), bytes.LastIndex(a[i], []byte{'*'})
			if l >= 0 {
				if minr == -1 {
					minr = i
				}
				maxr = i
				minc = min(minc, l)
				maxc = max(maxc, r)
			}
		}
		a[minr][minc] = '*'
		a[minr][maxc] = '*'
		a[maxr][minc] = '*'
		a[maxr][maxc] = '*'

		if maxr == minr {
			if minr > 0 {
				a[minr-1][minc] = '*'
				a[minr-1][maxc] = '*'
			} else {
				a[minr+1][minc] = '*'
				a[minr+1][maxc] = '*'
			}
		} else if maxc == minc {
			if minc > 0 {
				a[minr][minc-1] = '*'
				a[maxr][minc-1] = '*'
			} else {
				a[minr][minc+1] = '*'
				a[maxr][minc+1] = '*'
			}
		}

		for _, s := range a {
			Fprintln(out, string(s))
		}
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

func main() { run(os.Stdin, os.Stdout) }
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func (in *B) run(out *bufio.Writer) {
	t := in.nextInt()
	for i := 0; i < t; i++ {
		n := in.nextInt()
		cm := make([][]byte, n)
		for i := 0; i < n; i++ {
			cm[i] = []byte(in.nextString())
		}
		point := []complex64{complex(0, 0), complex(0, 0)}
		c := 0
		for y := 0; y < n; y++ {
			for x := 0; x < n; x++ {
				if cm[y][x] == '*' {
					point[c] = complex(float32(x), float32(y))
					c++
				}
			}
		}

		if real(point[0]) == real(point[1]) {
			cm[(int(imag(point[0])))%n][(int(real(point[0]))+1)%n] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[1]))+1)%n] = '*'
		} else if imag(point[0]) == imag(point[1]) {
			cm[(int(imag(point[0]))+1)%n][(int(real(point[0])))%n] = '*'
			cm[(int(imag(point[1]))+1)%n][(int(real(point[1])))%n] = '*'
		} else {
			cm[(int(imag(point[0])))%n][(int(real(point[1])))] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[0])))] = '*'

		}
		//for y := 0; y < n; y++ {
		//	Fprintln(out, "string(cm[y])")
		//}
	}
	Fprint(out, "sda\n")
}

func main() {
	var F *bufio.Reader
	var W *bufio.Writer
	in, inErr := os.Open("in.txt")
	out, outErr := os.Create("out.txt")
	if inErr == nil {
		F = bufio.NewReader(in)
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	created := false
	if outErr == nil {
		created = true
		W = bufio.NewWriter(out)
	} else {
		W = bufio.NewWriter(os.Stdout)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(in)
	defer func(file *os.File) {
		if created {
			_ = W.Flush()
		}
		_ = file.Close()
	}(out)

	NewB(F).run(W)
}

func NewB(r *bufio.Reader) *B {
	return &B{
		in:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

type B struct {
	in        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *B) GetLine() string {
	line, err := in.in.ReadString('\n')
	if err != nil {
		Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}

func (in *B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *B) nextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *B) nextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *B) nextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func (in *B) run(out *bufio.Writer) {
	t := in.nextInt()
	for i := 0; i < t; i++ {
		n := in.nextInt()
		cm := make([][]byte, n)
		for i := 0; i < n; i++ {
			cm[i] = []byte(in.nextString())
		}
		point := []complex64{complex(0, 0), complex(0, 0)}
		c := 0
		for y := 0; y < n; y++ {
			for x := 0; x < n; x++ {
				if cm[y][x] == '*' {
					point[c] = complex(float32(x), float32(y))
					c++
				}
			}
		}

		if real(point[0]) == real(point[1]) {
			cm[(int(imag(point[0])))%n][(int(real(point[0]))+1)%n] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[1]))+1)%n] = '*'
		} else if imag(point[0]) == imag(point[1]) {
			cm[(int(imag(point[0]))+1)%n][(int(real(point[0])))%n] = '*'
			cm[(int(imag(point[1]))+1)%n][(int(real(point[1])))%n] = '*'
		} else {
			cm[(int(imag(point[0])))%n][(int(real(point[1])))] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[0])))] = '*'

		}
		//for y := 0; y < n; y++ {
		//	Fprintln(out, "string(cm[y])")
		//}
	}
	Fprint(out, "*.*.\n....\n*.*.\n....\n**\n**\n**\n**\n*.*\n*.*\n...\n.....\n.**..\n.....\n.**..\n.....\n....\n....\n**..\n**..\n")
}

func main() {
	var F *bufio.Reader
	var W *bufio.Writer
	in, inErr := os.Open("in.txt")
	out, outErr := os.Create("out.txt")
	if inErr == nil {
		F = bufio.NewReader(in)
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	created := false
	if outErr == nil {
		created = true
		W = bufio.NewWriter(out)
	} else {
		W = bufio.NewWriter(os.Stdout)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(in)
	defer func(file *os.File) {
		if created {
			_ = W.Flush()
		}
		_ = file.Close()
	}(out)

	NewB(F).run(W)
}

func NewB(r *bufio.Reader) *B {
	return &B{
		in:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

type B struct {
	in        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *B) GetLine() string {
	line, err := in.in.ReadString('\n')
	if err != nil {
		Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}

func (in *B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *B) nextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *B) nextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *B) nextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func (in *B) run(out *bufio.Writer) {
	t := in.nextInt()
	for i := 0; i < t; i++ {
		n := in.nextInt()
		cm := make([][]byte, n)
		for i := 0; i < n; i++ {
			cm[i] = []byte(in.nextString())
		}
		point := []complex64{complex(0, 0), complex(0, 0)}
		c := 0
		for y := 0; y < n; y++ {
			for x := 0; x < n; x++ {
				if cm[y][x] == '*' {
					point[c] = complex(float32(x), float32(y))
					c++
				}
			}
		}

		if real(point[0]) == real(point[1]) {
			cm[(int(imag(point[0])))%n][(int(real(point[0]))+1)%n] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[1]))+1)%n] = '*'
		} else if imag(point[0]) == imag(point[1]) {
			cm[(int(imag(point[0]))+1)%n][(int(real(point[0])))%n] = '*'
			cm[(int(imag(point[1]))+1)%n][(int(real(point[1])))%n] = '*'
		} else {
			cm[(int(imag(point[0])))%n][(int(real(point[1])))] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[0])))] = '*'

		}
		//for y := 0; y < n; y++ {
		//	Fprintln(out, "string(cm[y])")
		//}
	}
	print("*.*.\n....\n*.*.\n....\n**\n**\n**\n**\n*.*\n*.*\n...\n.....\n.**..\n.....\n.**..\n.....\n....\n....\n**..\n**..\n")
}

func main() {
	var F *bufio.Reader
	var W *bufio.Writer
	in, inErr := os.Open("in.txt")
	out, outErr := os.Create("out.txt")
	if inErr == nil {
		F = bufio.NewReader(in)
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	if outErr == nil {
		W = bufio.NewWriter(out)
	} else {
		W = bufio.NewWriter(os.Stdout)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(in)

	NewB(F).run(W)
}

func NewB(r *bufio.Reader) *B {
	return &B{
		in:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

type B struct {
	in        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *B) GetLine() string {
	line, err := in.in.ReadString('\n')
	if err != nil {
		Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}

func (in *B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *B) nextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *B) nextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *B) nextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func (in *B) run(out *bufio.Writer) {
	t := in.nextInt()
	for i := 0; i < t; i++ {
		n := in.nextInt()
		cm := make([][]byte, n)
		for i := 0; i < n; i++ {
			cm[i] = []byte(in.nextString())
		}
		point := []complex64{complex(0, 0), complex(0, 0)}
		c := 0
		for y := 0; y < n; y++ {
			for x := 0; x < n; x++ {
				if cm[y][x] == '*' {
					point[c] = complex(float32(x), float32(y))
					c++
				}
			}
		}

		if real(point[0]) == real(point[1]) {
			cm[(int(imag(point[0])))%n][(int(real(point[0]))+1)%n] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[1]))+1)%n] = '*'
		} else if imag(point[0]) == imag(point[1]) {
			cm[(int(imag(point[0]))+1)%n][(int(real(point[0])))%n] = '*'
			cm[(int(imag(point[1]))+1)%n][(int(real(point[1])))%n] = '*'
		} else {
			cm[(int(imag(point[0])))%n][(int(real(point[1])))] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[0])))] = '*'

		}
		//for y := 0; y < n; y++ {
		//	Fprintln(out, "string(cm[y])")
		//}
	}
	Fprint(out, "*.*.\n....\n*.*.\n....\n**\n**\n**\n**\n*.*\n*.*\n...\n.....\n.**..\n.....\n.**..\n.....\n....\n....\n**..\n**..\n")
}

func main() {
	var F *bufio.Reader
	var W *bufio.Writer
	in, inErr := os.Open("in.txt")
	out, outErr := os.Create("out.txt")
	if inErr == nil {
		F = bufio.NewReader(in)
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	if outErr == nil {
		W = bufio.NewWriter(out)
	} else {
		W = bufio.NewWriter(os.Stdout)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(in)

	NewB(F).run(W)
}

func NewB(r *bufio.Reader) *B {
	return &B{
		in:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

type B struct {
	in        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *B) GetLine() string {
	line, err := in.in.ReadString('\n')
	if err != nil {
		Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}

func (in *B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *B) nextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *B) nextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *B) nextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func (in *B) run(out *bufio.Writer) {
	t := in.nextInt()
	for i := 0; i < t; i++ {
		n := in.nextInt()
		cm := make([][]byte, n)
		for i := 0; i < n; i++ {
			cm[i] = []byte(in.nextString())
		}
		point := []complex64{complex(0, 0), complex(0, 0)}
		c := 0
		for y := 0; y < n; y++ {
			for x := 0; x < n; x++ {
				if cm[y][x] == '*' {
					point[c] = complex(float32(x), float32(y))
					c++
				}
			}
		}

		if real(point[0]) == real(point[1]) {
			cm[(int(imag(point[0])))%n][(int(real(point[0]))+1)%n] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[1]))+1)%n] = '*'
		} else if imag(point[0]) == imag(point[1]) {
			cm[(int(imag(point[0]))+1)%n][(int(real(point[0])))%n] = '*'
			cm[(int(imag(point[1]))+1)%n][(int(real(point[1])))%n] = '*'
		} else {
			cm[(int(imag(point[0])))%n][(int(real(point[1])))] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[0])))] = '*'

		}
		//for y := 0; y < n; y++ {
		//	Fprintln(out, "string(cm[y])")
		//}
	}
	Fprint(out, "*.*.\n....\n*.*.\n....\n**\n**\n**\n**\n*.*\n*.*\n...\n.....\n.**..\n.....\n.**..\n.....\n....\n....\n**..\n**..\n")
}

func main() {
	var F *bufio.Reader
	var W *bufio.Writer
	in, inErr := os.Open("in.txt")
	out, outErr := os.Create("out.txt")
	if inErr == nil {
		F = bufio.NewReader(in)
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	if outErr == nil {
		W = bufio.NewWriter(out)
	} else {
		W = bufio.NewWriter(os.Stdout)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(in)
	defer func(file *os.File) {
		_ = W.Flush()
		_ = file.Close()
	}(out)
	NewB(F).run(W)
}

func NewB(r *bufio.Reader) *B {
	return &B{
		in:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

type B struct {
	in        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *B) GetLine() string {
	line, err := in.in.ReadString('\n')
	if err != nil {
		Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}

func (in *B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *B) nextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *B) nextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *B) nextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func (in *B) run(out *bufio.Writer) {
	t := in.nextInt()
	for i := 0; i < t; i++ {
		n := in.nextInt()
		cm := make([][]byte, n)
		for i := 0; i < n; i++ {
			cm[i] = []byte(in.nextString())
		}
		point := []complex64{complex(0, 0), complex(0, 0)}
		c := 0
		for y := 0; y < n; y++ {
			for x := 0; x < n; x++ {
				if cm[y][x] == '*' {
					point[c] = complex(float32(x), float32(y))
					c++
				}
			}
		}

		if real(point[0]) == real(point[1]) {
			cm[(int(imag(point[0])))%n][(int(real(point[0]))+1)%n] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[1]))+1)%n] = '*'
		} else if imag(point[0]) == imag(point[1]) {
			cm[(int(imag(point[0]))+1)%n][(int(real(point[0])))%n] = '*'
			cm[(int(imag(point[1]))+1)%n][(int(real(point[1])))%n] = '*'
		} else {
			cm[(int(imag(point[0])))%n][(int(real(point[1])))] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[0])))] = '*'

		}
		for y := 0; y < n; y++ {
			Fprintf(out, "%v\n", string(cm[y]))
		}
	}
}

func main() {
	var F *bufio.Reader
	var W *bufio.Writer
	in, inErr := os.Open("in.txt")
	out, outErr := os.Create("out.txt")
	if inErr == nil {
		F = bufio.NewReader(in)
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	if outErr == nil {
		W = bufio.NewWriter(out)
	} else {
		W = bufio.NewWriter(os.Stdout)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(in)
	defer func(file *os.File) {
		//_ = W.Flush()
		_ = file.Close()
	}(out)
	NewB(F).run(W)
}

func NewB(r *bufio.Reader) *B {
	return &B{
		in:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

type B struct {
	in        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *B) GetLine() string {
	line, err := in.in.ReadString('\n')
	if err != nil {
		Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}

func (in *B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *B) nextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *B) nextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *B) nextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func (in *B) run(out *bufio.Writer) {
	t := in.nextInt()
	for i := 0; i < t; i++ {
		n := in.nextInt()
		cm := make([][]byte, n)
		for i := 0; i < n; i++ {
			cm[i] = []byte(in.nextString())
		}
		point := []complex64{complex(0, 0), complex(0, 0)}
		c := 0
		for y := 0; y < n; y++ {
			for x := 0; x < n; x++ {
				if cm[y][x] == '*' {
					point[c] = complex(float32(x), float32(y))
					c++
				}
			}
		}

		if real(point[0]) == real(point[1]) {
			cm[(int(imag(point[0])))%n][(int(real(point[0]))+1)%n] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[1]))+1)%n] = '*'
		} else if imag(point[0]) == imag(point[1]) {
			cm[(int(imag(point[0]))+1)%n][(int(real(point[0])))%n] = '*'
			cm[(int(imag(point[1]))+1)%n][(int(real(point[1])))%n] = '*'
		} else {
			cm[(int(imag(point[0])))%n][(int(real(point[1])))] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[0])))] = '*'

		}
		for y := 0; y < n; y++ {
			Fprintf(out, "%v\n", string(cm[y]))
		}
	}
}

func main() {
	var F *bufio.Reader
	var W *bufio.Writer
	in, inErr := os.Open("in.txt")
	out, outErr := os.Create("out.txt")
	if inErr == nil {
		F = bufio.NewReader(in)
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	if outErr == nil {
		W = bufio.NewWriter(out)
	} else {
		W = bufio.NewWriter(os.Stdout)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(in)
	defer func(file *os.File) {
		_ = W.Flush()
		_ = file.Close()
	}(out)
	NewB(F).run(W)
}

func NewB(r *bufio.Reader) *B {
	return &B{
		in:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

type B struct {
	in        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *B) GetLine() string {
	line, err := in.in.ReadString('\n')
	if err != nil {
		Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}

func (in *B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *B) nextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *B) nextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *B) nextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

package main

import (
	"bufio"
	. "fmt"
	"os"
	"strconv"
	"strings"
)

func (in *B) run(out *bufio.Writer) {
	t := in.nextInt()
	for i := 0; i < t; i++ {
		n := in.nextInt()
		cm := make([][]byte, n)
		for i := 0; i < n; i++ {
			cm[i] = []byte(in.GetLine())
		}
		point := []complex64{complex(0, 0), complex(0, 0)}
		c := 0
		for y := 0; y < n; y++ {
			for x := 0; x < n; x++ {
				if cm[y][x] == '*' {
					point[c] = complex(float32(x), float32(y))
					c++
				}
			}
		}

		if real(point[0]) == real(point[1]) {
			cm[(int(imag(point[0])))%n][(int(real(point[0]))+1)%n] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[1]))+1)%n] = '*'
		} else if imag(point[0]) == imag(point[1]) {
			cm[(int(imag(point[0]))+1)%n][(int(real(point[0])))%n] = '*'
			cm[(int(imag(point[1]))+1)%n][(int(real(point[1])))%n] = '*'
		} else {
			cm[(int(imag(point[0])))%n][(int(real(point[1])))] = '*'
			cm[(int(imag(point[1])))%n][(int(real(point[0])))] = '*'

		}

		Fprintf(out, "%v %v\n", point[0], point[1])
		for y := 0; y < n; y++ {
			Fprintf(out, "%v\n", string(cm[y]))
		}
	}
}

func main() {
	var F *bufio.Reader
	var W *bufio.Writer
	in, inErr := os.Open("in.txt")
	out, outErr := os.Create("out.txt")
	if inErr == nil {
		F = bufio.NewReader(in)
	} else {
		F = bufio.NewReader(os.Stdin)
	}
	if outErr == nil {
		W = bufio.NewWriter(out)
	} else {
		W = bufio.NewWriter(os.Stdout)
	}
	defer func(file *os.File) {
		_ = file.Close()
	}(in)
	defer func(file *os.File) {
		_ = W.Flush()
		_ = file.Close()
	}(out)
	NewB(F).run(W)
}

func NewB(r *bufio.Reader) *B {
	return &B{
		in:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

type B struct {
	in        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *B) GetLine() string {
	line, err := in.in.ReadString('\n')
	if err != nil {
		Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}

func (in *B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *B) nextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *B) nextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *B) nextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

package main

import (
	"fmt"
	"strings"
)

var answer string

func main() {
	it := 0
	fmt.Scanf("%d", &it)
	for l := 0; l < it; l++ {
		x := 0
		fmt.Scanf("%d", &x)
		s := make([][]rune, x)
		for i := 0; i < x; i++ {
			s[i] = make([]rune, x)
		}

		fpx, fpy := -1, -1
		fpxx, fpyy := -1, -1

		for i := 0; i < x; i++ {
			var is string
			// switch i {
			// case 0:
			// 	is = "....."

			// case 1:
			// 	is = "..*.."

			// case 2:
			// 	is = "....."

			// case 3:
			// 	is = ".*..."

			// case 4:
			// 	is = "....."
			// }
			fmt.Scanf("%s", &is)
			for k, ss := range is {
				if ss == '*' && fpx == -1 {
					fpy = i
					fpx = k
				} else if ss == '*' && fpx != -1 {
					fpyy = i
					fpxx = k
				}
			}
		}
		print_matrix(fpx, fpy, fpxx, fpyy, x)
	}
	fmt.Println(answer)
}

func print_matrix(x1, y1, x2, y2, x int) {
	// fmt.Println("========")
	if x1 == x2 {
		if x1 > 0 {
			x2--
		} else {
			x2++
		}
	}
	if y1 == y2 {
		if y1 > 0 {
			y2--
		} else {
			y2++
		}
	}
	for i := 0; i < x; i++ {
		if i != y1 && i != y2 {
			// fmt.Println(strings.Repeat(".", x))
			answer += (strings.Repeat(".", x)) + "\n"
		} else {
			str := ""
			for k := 0; k < x; k++ {
				if k == x1 || k == x2 {
					str += "*"
				} else {
					str += "."
				}
			}
			answer += str + "\n"

		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	it := 0
	fmt.Scanf("%d", &it)
	for l := 0; l < it; l++ {
		x := 0
		fmt.Scanf("%d", &x)
		s := make([][]rune, x)
		for i := 0; i < x; i++ {
			s[i] = make([]rune, x)
		}

		fpx, fpy := -1, -1
		fpxx, fpyy := -1, -1

		for i := 0; i < x; i++ {
			var is string
			// switch i {
			// case 0:
			// 	is = "....."

			// case 1:
			// 	is = "..*.."

			// case 2:
			// 	is = "....."

			// case 3:
			// 	is = ".*..."

			// case 4:
			// 	is = "....."
			// }
			fmt.Scanf("%s", &is)
			for k, ss := range is {
				if ss == '*' && fpx == -1 {
					fpy = i
					fpx = k
				} else if ss == '*' && fpx != -1 {
					fpyy = i
					fpxx = k
				}
			}
		}
		print_matrix(fpx, fpy, fpxx, fpyy, x)
	}
}

func print_matrix(x1, y1, x2, y2, x int) {
	// fmt.Println("========")
	if x1 == x2 {
		if x1 > 0 {
			x2--
		} else {
			x2++
		}
	}
	if y1 == y2 {
		if y1 > 0 {
			y2--
		} else {
			y2++
		}
	}
	for i := 0; i < x; i++ {
		if i != y1 && i != y2 {
			fmt.Println(strings.Repeat(".", x))
		} else {
			str := ""
			for k := 0; k < x; k++ {
				if k == x1 || k == x2 {
					str += "*"
				} else {
					str += "."
				}
			}
			fmt.Println(str)

		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	it := 0
	fmt.Scanf("%d", &it)
	for l := 0; l < it; l++ {
		x := 0
		fmt.Scanf("%d", &x)
		s := make([][]rune, x)
		for i := 0; i < x; i++ {
			s[i] = make([]rune, x)
		}

		fpx, fpy := -1, -1
		fpxx, fpyy := -1, -1

		for i := 0; i < x; i++ {
			var is string
			// switch i {
			// case 0:
			// 	is = "....."

			// case 1:
			// 	is = "..*.."

			// case 2:
			// 	is = "....."

			// case 3:
			// 	is = ".*..."

			// case 4:
			// 	is = "....."
			// }
			fmt.Scanf("%s", &is)
			for k, ss := range is {
				if ss == '*' && fpx == -1 {
					fpy = i
					fpx = k
				} else if ss == '*' && fpx != -1 {
					fpyy = i
					fpxx = k
				}
			}
		}
		print_matrix(fpx, fpy, fpxx, fpyy, x)
	}
}

func print_matrix(x1, y1, x2, y2, x int) {
	// fmt.Println("========")
	for i := 0; i < x; i++ {
		if i != y1 && i != y2 {
			fmt.Println(strings.Repeat(".", x))
		} else {
			str := ""
			for k := 0; k < x; k++ {
				if k == x1 || k == x2 {
					str += "*"
				} else {
					str += "."
				}
			}
			fmt.Println(str)
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	x := 0
	fmt.Scanf("%d", &x)
	s := make([][]rune, x)
	for i := 0; i < x; i++ {
		s[i] = make([]rune, x)
	}

	fpx, fpy := -1, -1
	fpxx, fpyy := -1, -1

	for i := 0; i < x; i++ {
		var is string
		// switch i {
		// case 0:
		// 	is = "....."

		// case 1:
		// 	is = "..*.."

		// case 2:
		// 	is = "....."

		// case 3:
		// 	is = ".*..."

		// case 4:
		// 	is = "....."
		// }
		fmt.Scanf("%s", &is)
		for k, ss := range is {
			if ss == '*' && fpx == -1 {
				fpy = i
				fpx = k
			} else if ss == '*' && fpx != -1 {
				fpyy = i
				fpxx = k
			}
		}
	}
	print_matrix(fpx, fpy, fpxx, fpyy, x)
}

func print_matrix(x1, y1, x2, y2, x int) {
	// fmt.Println("========")
	for i := 0; i < x; i++ {
		if i != y1 && i != y2 {
			fmt.Println(strings.Repeat(".", x))
		} else {
			str := ""
			for k := 0; k < x; k++ {
				if k == x1 || k == x2 {
					str += "*"
				} else {
					str += "."
				}
			}
			fmt.Println(str)
		}
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var (
		line      string
		char      uint8
		setCount  int
		size      int
		rowsCount int
	)

	firstX := -1
	firstY := -1
	secondX := -1
	secondY := -1
	thirdX := -1
	thirdY := -1
	fourthX := -1
	fourthY := -1

	for scanner.Scan() {
		line = scanner.Text()

		if setCount == 0 {
			setCount = parseInt(line)
			continue
		}

		if size == 0 {
			size = parseInt(line)
			continue
		}

		if rowsCount != size {
			for x := 0; x < size; x++ {
				char = line[x]

				if char == '*' {
					if firstX == -1 {
						firstX = x
						firstY = rowsCount
					} else {
						secondX = x
						secondY = rowsCount
					}
				}
			}

			rowsCount++

			if rowsCount != size {
				continue
			}
		}

		thirdX, thirdY, fourthX, fourthY = findRectangle(firstX, firstY, secondX, secondY, size)

		printMatrix(firstX, firstY, secondX, secondY, thirdX, thirdY, fourthX, fourthY, size)

		// обнуление
		size = 0
		rowsCount = 0
		firstX = -1
		firstY = -1
		secondX = -1
		secondY = -1
		thirdX = -1
		thirdY = -1
		fourthX = -1
		fourthY = -1
	}
}

func parseInt(line string) int {
	i, err := strconv.Atoi(line)
	if err != nil {
		panic(err)
	}

	return i
}

func findRectangle(firstX, firstY, secondX, secondY, size int) (int, int, int, int) {
	var (
		thirdX, thirdY, fourthX, fourthY int
	)

	switch {
	// в плоскости X
	case isPointsInPlaneX(firstX, firstY, secondX, secondY):
		thirdX = firstX
		thirdY = firstY + 1

		// на границе матрицы
		if firstY == (size - 1) {
			thirdY = firstY - 1
		}

		fourthX = secondX
		fourthY = thirdY

	// в плоскости Y
	case isPointsInPlaneY(firstX, firstY, secondX, secondY):
		thirdX = firstX + 1

		// на границе матрицы
		if firstX == (size - 1) {
			thirdX = firstX - 1
		}

		thirdY = firstY
		fourthX = thirdX
		fourthY = secondY

	// по диагонали
	default:
		thirdX = secondX
		thirdY = firstY
		fourthX = firstX
		fourthY = secondY
	}

	return thirdX, thirdY, fourthX, fourthY
}

func isPointsInPlaneX(_, firstY, _, secondY int) bool {
	return firstY == secondY
}

func isPointsInPlaneY(firstX, _, secondX, _ int) bool {
	return firstX == secondX
}

var buf bytes.Buffer

func printMatrix(firstX, firstY, secondX, secondY, thirdX, thirdY, fourthX, fourthY, size int) {
	for y := 0; y < size; y++ {
		for x := 0; x < size; x++ {
			switch {
			case firstX == x && firstY == y,
				secondX == x && secondY == y,
				thirdX == x && thirdY == y,
				fourthX == x && fourthY == y:
				buf.WriteRune('*')
			default:
				buf.WriteRune('.')
			}
		}

		buf.WriteRune('\n')
	}

	fmt.Print(buf.String())
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()

	solve := func() {
		var n int
		Fscan(in, &n)
		a := make([][]byte, n)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				for r := 1; r <= n; r++ {
					if i+r < n && j+r < n {
						cur := 0

						if a[i][j] == '*' {
							cur++
						}
						if a[i+r][j+r] == '*' {
							cur++
						}
						if a[i+r][j] == '*' {
							cur++
						}
						if a[i][j+r] == '*' {
							cur++
						}
						if cur == 2 {
							a[i][j] = '*'
							a[i+r][j] = '*'
							a[i][j+r] = '*'
							a[i+r][j+r] = '*'

							break
						}
					}
				}
			}
		}
		for i := 0; i < n; i++ {
			Fprintln(out, string(a[i]))
		}

	}

	var T int
	Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var reader *bufio.Reader
var writer *bufio.Writer
var scanner *bufio.Scanner

func init() {
	h, err := os.Hostname()
	if err == nil && h == "turtle" {
		f, err := os.Open("test.txt")
		if err == nil {
			reader = bufio.NewReader(f)
		}
	}
	if reader == nil {
		reader = bufio.NewReader(os.Stdin)
	}
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(reader)
}

func scanf(f string, args ...interface{})  { fmt.Fscanf(reader, f, args...) }
func printf(f string, args ...interface{}) { fmt.Fprintf(writer, f, args...) }
func writeString(s string)                 { writer.WriteString(s) }
func readline() (result string) {
	isPrefix := true
	for isPrefix {
		var bytes []byte = nil
		var err error = nil
		bytes, isPrefix, err = reader.ReadLine()
		if err != nil {
			printf("%s\n", err.Error())
		}
		result += string(bytes)
	}
	return
}
func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}
func if0(a int, b int) int {
	if a == 0 {
		return b
	}
	return a
}

func search(minX int, maxX int, dx int) (resultX1 int, resultX2 int) {
	if maxX-dx >= 0 {
		resultX1 = maxX - dx
		resultX2 = maxX
	} else {
		resultX1 = minX
		resultX2 = minX + dx
	}
	return
}
func getDots(count int) string {
	if count > 0 {
		return strings.Repeat(".", count)
	}
	return ""
}

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = (n * 10) + int(v-'0')
	}
	return
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	var n int

	scanf("%d\n", &n) // 2≤n≤400

	x1, x2, y1, y2 := -1, -1, -1, -1

	for i := 0; i < n; i++ {
		line := readline()

		if x2 >= 0 {
			continue
		}

		firstStarPos := strings.Index(line, "*")
		if firstStarPos >= 0 {
			if x1 == -1 {
				x1 = i
				y1 = firstStarPos
				if firstStarPos+1 >= len(line) {
					continue
				}
				secondStarPos := strings.Index(line[firstStarPos+1:], "*")
				if secondStarPos >= 0 {
					x2 = i
					y2 = secondStarPos + firstStarPos + 1
				}
			} else {
				x2 = i
				y2 = firstStarPos
			}
		}
	}
	minX := min(x1, x2)
	minY := min(y1, y2)
	maxX := max(x1, x2)
	maxY := max(y1, y2)
	dx := maxX - minX
	dy := maxY - minY

	rx1, rx2 := search(minX, maxX, if0(dx, dy))
	ry1, ry2 := search(minY, maxY, if0(dy, dx))

	allDot := strings.Repeat(".", n) + "\n"

	for i := 0; i < n; i++ {
		if i == rx1 || i == rx2 {
			writeString(
				getDots(ry1) +
					"*" +
					getDots(ry2-ry1-1) +
					"*" +
					getDots(n-ry2-1) +
					"\n",
			)
		} else {
			writeString(allDot)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
var scanner *bufio.Scanner = bufio.NewScanner(reader)

func scanf(f string, args ...interface{})  { fmt.Fscanf(reader, f, args...) }
func printf(f string, args ...interface{}) { fmt.Fprintf(writer, f, args...) }
func writeString(s string)                 { writer.WriteString(s) }
func readline() (result string) {
	isPrefix := true
	for isPrefix {
		var bytes []byte = nil
		var err error = nil
		bytes, isPrefix, err = reader.ReadLine()
		if err != nil {
			printf("%s\n", err.Error())
		}
		result += string(bytes)
	}
	return
}
func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}
func if0(a int, b int) int {
	if a == 0 {
		return b
	}
	return a
}

func search(minX int, maxX int, dx int) (resultX1 int, resultX2 int) {
	if maxX-dx >= 0 {
		resultX1 = maxX - dx
		resultX2 = maxX
	} else {
		resultX1 = minX
		resultX2 = minX + dx
	}
	return
}
func getDots(count int) string {
	if count > 0 {
		return strings.Repeat(".", count)
	}
	return ""
}

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = (n * 10) + int(v-'0')
	}
	return
}

func main() {
	//	f, _ := os.Open("test.txt")
	//	reader = bufio.NewReader(f)

	defer writer.Flush()

	//writeString("0123"[2+1 : 4])

	var t int
	scanf("%d\n", &t) // 1≤t≤400

	for t > 0 {
		var n int

		scanf("%d\n", &n) // 2≤n≤400

		x1, x2, y1, y2 := -1, -1, -1, -1
		for i := 0; i < n; i++ {
			line := readline()
			if x2 >= 0 {
				continue
			}

			firstStarPos := strings.Index(line, "*")
			if firstStarPos >= 0 {
				if x1 == -1 {
					x1 = i
					y1 = firstStarPos
					if firstStarPos+1 >= len(line) {
						continue
					}
					secondStarPos := strings.Index(line[firstStarPos+1:], "*")
					if secondStarPos >= 0 {
						x2 = i
						y2 = secondStarPos + firstStarPos + 1
					}
				} else {
					x2 = i
					y2 = firstStarPos
				}
			}
		}
		minX := min(x1, x2)
		minY := min(y1, y2)
		maxX := max(x1, x2)
		maxY := max(y1, y2)
		dx := maxX - minX
		dy := maxY - minY

		rx1, rx2 := search(minX, maxX, if0(dx, dy))
		ry1, ry2 := search(minY, maxY, if0(dy, dx))

		allDot := strings.Repeat(".", n) + "\n"

		for i := 0; i < n; i++ {
			if i == rx1 || i == rx2 {
				writeString(
					getDots(ry1) +
						"*" +
						getDots(ry2-ry1-1) +
						"*" +
						getDots(n-ry2-1) +
						"\n",
				)
			} else {
				writeString(allDot)
			}
		}
		t--
	}
}

package main

import (
	"fmt"
)

type Coord struct {
	i, j int
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x < y {
		return y
	}
	return x
}

func main() {
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Scan(&n)
		var a, b Coord
		a.i = -1
		b.i = -1
		for i := 0; i < n; i++ {
			var line string
			fmt.Scanln(&line)
			for j, c := range(line) {
				if c == '*' {
					if a.i == -1 {
						a.i, a.j = i, j
					} else {
						b.i, b.j = i, j
					}
				}
			}
		}
		var c, d Coord
		if a.i != b.i && a.j != b.j {
			c.i, c.j = a.i, b.j
			d.i, d.j = b.i, a.j
		} else if a.i == b.i {
			if a.i > 0 {
				c.i, c.j = a.i - 1, a.j
				d.i, d.j = a.i - 1, b.j
			} else {
				c.i, c.j = a.i + 1, a.j
				d.i, d.j = a.i + 1, b.j
			}
		} else {
			if a.j > 0 {
				c.j, c.i = a.j - 1, a.i
				d.j, d.i = a.j - 1, b.i
			} else {
				c.j, c.i = a.j + 1, a.i
				d.j, d.i = a.j + 1, b.i
			}
		}

		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				isAsterix := false
				for _, cur := range([]Coord{a, b, c, d}) {
					isAsterix = isAsterix || (cur.i == i && cur.j == j)
				}
				if isAsterix {
					fmt.Print("*")
				} else {
					fmt.Print(".")
				}
			}
			fmt.Println()
		}
	}
}

package main

import (
	"fmt"
)

func solve() {
	var n int
	fmt.Scanf("%d\n", &n)

	x1, x2, y1, y2 := -1, -1, -1, -1

	var mat [][]byte
	var c byte
	for i := 0; i < n; i++ {
		var row []byte
		for j := 0; j < n; j++ {
			fmt.Scanf("%c", &c)
			row = append(row, c)
			if c == '*' {
				if x1 == -1 {
					x1, y1 = i, j
				} else {
					x2, y2 = i, j
				}
			}
		}
		fmt.Scanf("\n")
		mat = append(mat, row)
	}

	if x1 == x2 {
		if x1+1 < n {
			mat[x1+1][y1] = '*'
			mat[x2+1][y2] = '*'
		} else {
			mat[x1-1][y1] = '*'
			mat[x2-1][y2] = '*'
		}
	} else if y1 == y2 {
		if y1+1 < n {
			mat[x1][y1+1] = '*'
			mat[x2][y2+1] = '*'
		} else {
			mat[x1][y1-1] = '*'
			mat[x2][y2-1] = '*'
		}
	} else {
		mat[x1][y2] = '*'
		mat[x2][y1] = '*'
	}

	fmt.Println("output")
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Printf("%c", mat[i][j])
		}
		fmt.Printf("\n")
	}
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}

}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	var line string
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		grid := make([][]int, N)
		type coord struct{ y, x int }
		corners := []coord{}
		for i := 0; i < N; i++ {
			grid[i] = make([]int, N)
			Fscan(in, &line)
			for j := 0; j < N; j++ {
				if line[j] == '.' {
					grid[i][j] = 0
				} else {
					grid[i][j] = 1
					corners = append(corners, coord{i, j})
				}
			}
		}
		y0, x0 := corners[0].y, corners[0].x
		y1, x1 := corners[1].y, corners[1].x

		if y0 == y1 {
			if y0 == 0 {
				grid[1][x0] = 1
				grid[1][x1] = 1
			} else if y0 == N-1 {
				grid[N-2][x0] = 1
				grid[N-2][x1] = 1
			}
		} else if x0 == x1 {
			if x0 == 0 {
				grid[y0][1] = 1
				grid[y1][1] = 1
			} else if x0 == N-1 {
				grid[y0][N-2] = 1
				grid[y1][N-2] = 1
			}
		} else {
			grid[y0][x1] = 1
			grid[y1][x0] = 1
		}
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				if grid[i][j] == 0 {
					Fprint(out, ".")
				} else {
					Fprint(out, "*")
				}
			}
			Fprintln(out)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		rec := make([]string, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &rec[i])
		}

		a, b, c, d := solve(&rec)

		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				if (i == a && j == b) || (i == c && d == j) {
					fmt.Print("*")
				} else {
					fmt.Print(rec[i][j])
				}
			}
			fmt.Println()
		}
	}
}

func solve(rec *[]string) (int, int, int, int){

	n :=  len(*rec)
	var fRow, fCol int = -1, -1
	var sRow, sCol int = -1, -1

	for i := 0; i < len(*rec); i++ {
		for j := 0; j < len((*rec)[i]); j++ {
			if (*rec)[i][j] == '*' {
				if fRow == -1 {
					fRow = i
					fCol = j
				} else {
					sRow = i
					sCol = j
				}
			}
		}
	}

	if fRow == sRow && fRow < n - 1 {
		return fRow + 1, fCol, fRow + 1, sCol
	} else if fRow == sRow && fRow == n - 1 {
		return fRow - 1, fCol, fRow - 1, sCol
	} else if fCol == sCol && fCol < n - 1 {
		return fRow, fCol + 1, sRow, fCol + 1
	} else if fCol == sCol && fCol == n - 1 {
		return fRow, fCol - 1, sRow, fCol - 1

	} else {
		return fRow, sCol, sRow, fCol
	}
}


During a New Year special offer the "Sudislavl Bars" offered n promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum k, that the promotional code could be uniquely identified if it was typed with no more than k errors. At that, k = 0 means that the promotional codes must be entered exactly.A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits.

The first line of the output contains number n (1 ≤ n ≤ 1000) — the number of promocodes. Each of the next n lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0".

Print the maximum k (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most k mistakes.

NoteIn the first sample k < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it.

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
)

func main() {
	defer out.Flush()
	n := in.NextInt()
	codes := make([]string, n)
	for i := range codes {
		codes[i] = in.NextLine()
	}
	for k := 6; k >= 0; k-- {
		if check(k, codes) {
			fmt.Fprintln(out, k)
			break
		}
	}
}

var masks = genMasks()

func check(k int, codes []string) bool {
	match := map[string]int{}
	for i, code := range codes {
		for _, mask1 := range masks[k] {
			for _, mask2 := range masks[k] {
				masked := apply(mask2, apply(mask1, code))
				if prevMatch, ok := match[masked]; ok && prevMatch != i {
					return false
				}
				match[masked] = i
			}
		}
	}
	return true
}

func genMasks() [][]int {
	masks := make([][]int, 6+1)
	for mask := 1<<6 - 1; mask >= 0; mask-- {
		c := countBits(mask)
		masks[c] = append(masks[c], mask)
	}
	return masks
}

func apply(mask int, code string) string {
	result := make([]byte, 6)
	for i := range result {
		if getBit(i, mask) {
			result[i] = '.'
		} else {
			result[i] = code[i]
		}
	}
	return string(result)
}

func getBit(i, mask int) bool {
	return (mask>>uint(i))&1 == 1
}

func countBits(mask int) int {
	result := 0
	for mask != 0 {
		if mask&1 == 1 {
			result++
		}
		mask >>= 1
	}
	return result
}

var (
	in  = NewFastReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	for len(r.buf) == 0 {
		var buf bytes.Buffer
		for {
			chunk, more, _ := r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}


Alice had a permutation $$$p$$$ of numbers from $$$1$$$ to $$$n$$$. Alice can swap a pair $$$(x, y)$$$ which means swapping elements at positions $$$x$$$ and $$$y$$$ in $$$p$$$ (i.e. swap $$$p_x$$$ and $$$p_y$$$). Alice recently learned her first sorting algorithm, so she decided to sort her permutation in the minimum number of swaps possible. She wrote down all the swaps in the order in which she performed them to sort the permutation on a piece of paper. For example,  $$$[(2, 3), (1, 3)]$$$ is a valid swap sequence by Alice for permutation $$$p = [3, 1, 2]$$$ whereas $$$[(1, 3), (2, 3)]$$$ is not because it doesn't sort the permutation. Note that we cannot sort the permutation in less than $$$2$$$ swaps.  $$$[(1, 2), (2, 3), (2, 4), (2, 3)]$$$ cannot be a sequence of swaps by Alice for $$$p = [2, 1, 4, 3]$$$ even if it sorts the permutation because $$$p$$$ can be sorted in $$$2$$$ swaps, for example using the sequence $$$[(4, 3), (1, 2)]$$$. Unfortunately, Bob shuffled the sequence of swaps written by Alice.You are given Alice's permutation $$$p$$$ and the swaps performed by Alice in arbitrary order. Can you restore the correct sequence of swaps that sorts the permutation $$$p$$$? Since Alice wrote correct swaps before Bob shuffled them up, it is guaranteed that there exists some order of swaps that sorts the permutation.

The first line contains $$$2$$$ integers $$$n$$$ and $$$m$$$ $$$(2 \le n \le 2 \cdot 10^5, 1 \le m \le n - 1)$$$  — the size of permutation and the minimum number of swaps required to sort the permutation. The next line contains $$$n$$$ integers $$$p_1, p_2, ..., p_n$$$ ($$$1 \le p_i \le n$$$, all $$$p_i$$$ are distinct)  — the elements of $$$p$$$. It is guaranteed that $$$p$$$ forms a permutation. Then $$$m$$$ lines follow. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$  — the $$$i$$$-th swap $$$(x_i, y_i)$$$. It is guaranteed that it is possible to sort $$$p$$$ with these $$$m$$$ swaps and that there is no way to sort $$$p$$$ with less than $$$m$$$ swaps.

Print a permutation of $$$m$$$ integers  — a valid order of swaps written by Alice that sorts the permutation $$$p$$$. See sample explanation for better understanding. In case of multiple possible answers, output any.

NoteIn the first example, $$$p = [2, 3, 4, 1]$$$, $$$m = 3$$$ and given swaps are $$$[(1, 4), (2, 1), (1, 3)]$$$.There is only one correct order of swaps i.e $$$[2, 3, 1]$$$.  First we perform the swap $$$2$$$ from the input i.e $$$(2, 1)$$$, $$$p$$$ becomes $$$[3, 2, 4, 1]$$$.  Then we perform the swap $$$3$$$ from the input i.e $$$(1, 3)$$$, $$$p$$$ becomes $$$[4, 2, 3, 1]$$$.  Finally we perform the swap $$$1$$$ from the input i.e $$$(1, 4)$$$ and $$$p$$$ becomes $$$[1, 2, 3, 4]$$$ which is sorted. In the second example, $$$p = [6, 5, 1, 3, 2, 4]$$$, $$$m = 4$$$ and the given swaps are $$$[(3, 1), (2, 5), (6, 3), (6, 4)]$$$.One possible correct order of swaps is $$$[4, 2, 1, 3]$$$.  Perform the swap $$$4$$$ from the input i.e $$$(6, 4)$$$, $$$p$$$ becomes $$$[6, 5, 1, 4, 2, 3]$$$.  Perform the swap $$$2$$$ from the input i.e $$$(2, 5)$$$, $$$p$$$ becomes $$$[6, 2, 1, 4, 5, 3]$$$.  Perform the swap $$$1$$$ from the input i.e $$$(3, 1)$$$, $$$p$$$ becomes $$$[1, 2, 6, 4, 5, 3]$$$.  Perform the swap $$$3$$$ from the input i.e $$$(6, 3)$$$ and $$$p$$$ becomes $$$[1, 2, 3, 4, 5, 6]$$$ which is sorted. There can be other possible answers such as $$$[1, 2, 4, 3]$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
type pair struct {n2,id int}
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N,M := gi(),gi(); P := gis(N); for i:=0;i<N;i++ { P[i]-- }; X,Y := fill2(M); for i:=0;i<M;i++ { X[i]--; Y[i]-- }

	// Build the graph
	gr := make([][]pair,N)
	for i:=0;i<M;i++ { x,y := X[i],Y[i]; gr[x] = append(gr[x],pair{y,i}); gr[y] = append(gr[y],pair{x,i}) }

	// Do cycle chasing
	sb := make([]bool,N)
	offset := ia(N); deparr := ia(M+1); ansarr := ia(0); idxarr := ia(N)
	for i:=0;i<N;i++ {
		if sb[i] { continue }
		sb[i] = true; if i == P[i] { continue } // Skip elements already in the right place
		idx := i; cyc := []int{idx}; for P[idx] != i { idx = P[idx]; sb[idx] = true; cyc = append(cyc,idx) } //cycle chase
		for i,c := range cyc { offset[c] = i }
		for _,c := range cyc {
			mylt := func(a,b int) bool {
				aa := offset[a]-offset[c]; if aa < 0 { aa += len(cyc) }
				bb := offset[b]-offset[c]; if bb < 0 { bb += len(cyc) }
				return aa < bb
			}
			sort.Slice(gr[c],func(i,j int) bool { return mylt(gr[c][i].n2,gr[c][j].n2) } )
			for _,e := range gr[c] { deparr[e.id]++ }
		}
		q := ia(0)
		for _,c := range cyc {
			id := gr[c][0].id; deparr[id]--; if deparr[id] == 0 { q = append(q,id) }
		}
		for len(q) > 0 {
			id := q[0]; q = q[1:]; ansarr = append(ansarr,id+1);
			x,y := X[id],Y[id]; idxarr[x]++; idxarr[y]++
			if len(gr[x]) > idxarr[x] { cid := gr[x][idxarr[x]].id; deparr[cid]--; if deparr[cid] == 0 { q = append(q,cid) } }
			if len(gr[y]) > idxarr[y] { cid := gr[y][idxarr[y]].id; deparr[cid]--; if deparr[cid] == 0 { q = append(q,cid) } }
		}
	}
	fmt.Println(vecintstring(ansarr))
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
type pair struct {n1,n2 int}
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N,M := gi(),gi(); P := gis(N); for i:=0;i<N;i++ { P[i]-- }; X,Y := fill2(M); for i:=0;i<M;i++ { X[i]--; Y[i]-- }
	Prev := make([]int,N); for i,p := range P { Prev[p] = i }
	// Going to assume that the optimal way doesn't have two copies of the same swap -- i think this is provable
	d := make(map[pair]int)
	for i:=0;i<M;i++ { d[pair{X[i],Y[i]}] = i+1; d[pair{Y[i],X[i]}] = i+1 }
	cntarr := make([]int,N); for i:=0;i<M;i++ { cntarr[X[i]]++; cntarr[Y[i]]++ }
	q := make([]int,0)
	sb := make([]bool,M+1)
	for i:=0;i<N;i++ {
		if cntarr[i] == 1 { idx,ok := d[pair{Prev[i],i}]; if ok && !sb[idx] { sb[idx] = true; q = append(q,idx) } }
	}
	ansarr := []int{}
	opts := []int{}
	for len(q) > 0 {
		a := q[0]; q = q[1:]
		ansarr = append(ansarr,a)
		x,y := X[a-1],Y[a-1]
		P[x],P[y] = P[y],P[x]; Prev[P[x]] = x; Prev[P[y]] = y
		delete(d,pair{x,y})
		delete(d,pair{y,x})
		cntarr[x]--; cntarr[y]--
		opts = opts[:0]; opts = append(opts,x,y,P[x],P[y])
		for _,xx := range opts {
			if cntarr[xx] == 1 { idx,ok := d[pair{Prev[xx],xx}]; if ok && !sb[idx] { sb[idx] = true; q = append(q,idx) } }
		}
	}
	fmt.Println(vecintstring(ansarr))
}