In Ancient Berland there were n cities and m two-way roads of equal length. The cities are numbered with integers from 1 to n inclusively. According to an ancient superstition, if a traveller visits three cities ai, bi, ci in row, without visiting other cities between them, a great disaster awaits him. Overall there are k such city triplets. Each triplet is ordered, which means that, for example, you are allowed to visit the cities in the following order: ai, ci, bi. Vasya wants to get from the city 1 to the city n and not fulfil the superstition. Find out which minimal number of roads he should take. Also you are required to find one of his possible path routes.

The first line contains three integers n, m, k (2 ≤ n ≤ 3000, 1 ≤ m ≤ 20000, 0 ≤ k ≤ 105) which are the number of cities, the number of roads and the number of the forbidden triplets correspondingly.  Then follow m lines each containing two integers xi, yi (1 ≤ xi, yi ≤ n) which are the road descriptions. The road is described by the numbers of the cities it joins. No road joins a city with itself, there cannot be more than one road between a pair of cities.  Then follow k lines each containing three integers ai, bi, ci (1 ≤ ai, bi, ci ≤ n) which are the forbidden triplets. Each ordered triplet is listed mo more than one time. All three cities in each triplet are distinct. City n can be unreachable from city 1 by roads.

If there are no path from 1 to n print -1. Otherwise on the first line print the number of roads d along the shortest path from the city 1 to the city n. On the second line print d + 1 numbers — any of the possible shortest paths for Vasya. The path should start in the city 1 and end in the city n.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

type Edge struct {
	from, to, next int
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewReader(bs)
	var n, m, k int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &k)

	firstEdge := make([]int, n)
	edges := make([]Edge, 0, 2*m)
	dist := make([]int, 2*m)
	from := make([]int, 2*m)
	for i := 0; i < n; i++ {
		firstEdge[i] = -1
	}
	for i := 0; i < 2*m; i++ {
		dist[i], from[i] = -1, -1
	}

	for i := 0; i < m; i++ {
		var x, y int
		fmt.Fscanf(reader, "%d %d\n", &x, &y)
		x, y = x-1, y-1
		edges, firstEdge[x] = append(edges, Edge{x, y, firstEdge[x]}), i*2
		edges, firstEdge[y] = append(edges, Edge{y, x, firstEdge[y]}), i*2+1
	}

	tabu := map[uint64]bool{}

	for i := 0; i < k; i++ {
		var a, b, c uint64
		fmt.Fscanf(reader, "%d %d %d\n", &a, &b, &c)
		a, b, c = a-1, b-1, c-1
		tabu[(a<<24)+(b<<12)+c] = true
	}

	queue := []int{}
	for e := firstEdge[0]; e != -1; e = edges[e].next {
		dist[e] = 1
		queue = append(queue, e)
	}

	for len(queue) > 0 {
		start := edges[queue[0]]
		mask := (uint64(start.from) << 24) + (uint64(start.to) << 12)
		for e := firstEdge[start.to]; e != -1; e = edges[e].next {
			if _, ok := tabu[mask+uint64(edges[e].to)]; !ok && (dist[e] == -1 || dist[e] > dist[queue[0]]+1) {
				dist[e] = dist[queue[0]] + 1
				from[e] = queue[0]
				queue = append(queue, e)
			}
		}
		queue = queue[1:]
	}

	best, beste := 9999999, -1

	for i := 0; i < 2*m; i++ {
		if edges[i].to == n-1 && dist[i] != -1 && dist[i] < best {
			best, beste = dist[i], i
		}
	}
	if beste == -1 {
		fmt.Printf("-1")
	} else {
		fmt.Printf("%d\n", best)
		path := []int{n - 1}
		for e := beste; e != -1; e = from[e] {
			path = append(path, edges[e].from)
		}
		for i := len(path) - 1; i >= 0; i-- {
			fmt.Printf("%d ", path[i]+1)
		}
	}

}

package main

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

var (
	reader *bufio.Reader = bufio.NewReader(os.Stdin)
	writer *bufio.Writer = bufio.NewWriter(os.Stdout)
	Debug                = true
)

func Printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func Scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

type tri struct {
	a, b, c int
}

type ij struct {
	i, j int
}

var (
	n, m, k int

	adj  [][]int
	forb = make(map[tri]bool)

	visit  []ij
	dists  = make(map[ij]int)
	prevIJ = make(map[ij]int)
)

func main() {
	defer writer.Flush()

	// Read input.
	Scanf("%d %d %d\n", &n, &m, &k)

	adj = make([][]int, n+1)
	for i := 0; i < m; i++ {
		var xi, yi int
		Scanf("%d %d\n", &xi, &yi)
		adj[xi] = append(adj[xi], yi)
		adj[yi] = append(adj[yi], xi)
	}

	for i := 0; i < k; i++ {
		var ai, bi, ci int
		Scanf("%d %d %d\n", &ai, &bi, &ci)
		forb[tri{ai, bi, ci}] = true
	}

	// Dijkstra, visit starting from visit starting from city 1.
	visit = []ij{{1, 1}}
	dists[ij{1, 1}] = 0
	dijkstra()

	// Find the way back.
	minDist := math.MaxInt32
	var minIJ ij
	for curIJ, d := range dists {
		if curIJ.j == n {
			if d < minDist {
				minDist = d
				minIJ = curIJ
			}
		}
	}

	if minDist == math.MaxInt32 {
		Printf("-1\n")
		return
	}

	path := []int{n}
	curIJ := minIJ
	for curIJ.j != 1 {
		path = append(path, curIJ.i)
		curIJ = ij{prevIJ[curIJ], curIJ.i}
	}
	Printf("%d\n", len(path)-1)
	for i := len(path) - 1; i >= 0; i-- {
		Printf("%d ", path[i])
	}
}

func dijkstra() {
	for len(visit) > 0 {
		// cur is j before i.
		cur := visit[0]
		visit = visit[1:]

		for _, nex := range adj[cur.j] {
			jNex := ij{cur.j, nex}
			if _, ok := dists[jNex]; ok {
				// d(j,nex) has already been calculated.
				continue
			}
			if forb[tri{cur.i, cur.j, nex}] {
				// i, j, nex is forbidden.
				continue
			}
			dists[jNex] = dists[cur] + 1
			prevIJ[jNex] = cur.i
			visit = append(visit, jNex)
		}
	}
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

type Edge struct {
	from, to, next int
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewReader(bs)
	var n, m, k int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &k)

	firstEdge := make([]int, n)
	edges := make([]Edge, 0, 2*m)
	dist := make([]int, 2*m)
	from := make([]int, 2*m)
	for i := 0; i < n; i++ {
		firstEdge[i] = -1
	}
	for i := 0; i < 2*m; i++ {
		dist[i], from[i] = -1, -1
	}

	for i := 0; i < m; i++ {
		var x, y int
		fmt.Fscanf(reader, "%d %d\n", &x, &y)
		x, y = x-1, y-1
		edges, firstEdge[x] = append(edges, Edge{x, y, firstEdge[x]}), i*2
		edges, firstEdge[y] = append(edges, Edge{y, x, firstEdge[y]}), i*2+1
	}

	tabu := map[uint64]bool{}

	for i := 0; i < k; i++ {
		var a, b, c uint64
		fmt.Fscanf(reader, "%d %d %d\n", &a, &b, &c)
		a, b, c = a-1, b-1, c-1
		tabu[(a<<24)+(b<<12)+c] = true
	}

	queue := []int{}
	for e := firstEdge[0]; e != -1; e = edges[e].next {
		dist[e] = 1
		queue = append(queue, e)
	}

	for len(queue) > 0 {
		start := edges[queue[0]]
		mask := (uint64(start.from) << 24) + (uint64(start.to) << 12)
		for e := firstEdge[start.to]; e != -1; e = edges[e].next {
			if _, ok := tabu[mask+uint64(edges[e].to)]; !ok && (dist[e] == -1 || dist[e] > dist[queue[0]]+1) {
				dist[e] = dist[queue[0]] + 1
				from[e] = queue[0]
				queue = append(queue, e)
			}
		}
		queue = queue[1:]
	}

	best, beste := 9999999, -1

	for i := 0; i < 2*m; i++ {
		if edges[i].next == n-1 && dist[i] != -1 && dist[i] < best {
			best, beste = dist[i], i
		}
	}
	if beste == -1 {
		fmt.Printf("-1")
	} else {
		fmt.Printf("%d\n", best)
		path := []int{n - 1}
		for e := beste; e != -1; e = from[e] {
			path = append(path, edges[e].from)
		}
		for i := len(path) - 1; i >= 0; i-- {
			fmt.Printf("%d ", path[i]+1)
		}
	}

}


You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which:  Any number in this field is in range $$$[1; 9]$$$;  each row contains at least two equal elements;  each column contains at least two equal elements;  each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle.

For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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 scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

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

var toBe = []int{0, 3, 6, 1, 4, 7, 2, 5, 8}

func exec() {
	field := make([][]int, 9)
	for i := 0; i < 9; i++ {
		field[i] = make([]int, 9)
		str, err := reader.ReadString('\n')
		if err != nil {
			fmt.Println(err.Error())
			panic(err)
		}
		str = strings.TrimRight(str, "\n\r")
		for j, s := range []byte(str) {
			if toBe[i] != j {
				printf("%s", string(s))
				continue
			}
			num, err := strconv.ParseInt(string(s), 10, 64)
			if err != nil {
				fmt.Println(err.Error())
				panic(err)
			}
			num -= 9
			if num == 0 {
				num = 1
			}
			printf("%d", int(math.Abs(float64(num))))
		}
		printf("\n")
	}
}

package main

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

var scanner *bufio.Scanner

func solve() {
	input := make([][]byte, 9)
	for i := 0; i < 9; i++ {
		input[i] = []byte(getString())
	}

	for i := 0; i < 9; i++ {
		for j := 0; j < 9; j++ {
			if input[i][j] == '1' {
				input[i][j] ='2'
			}
		}
	}
	for i := 0; i < 9; i++{
		fmt.Println(string(input[i]))
	}
}

func main() {

	f, err := os.Open("input.txt")
	if err == nil {
		os.Stdin = f
	}
	defer f.Close()

	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	t := fs()

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

func fs() int {
	if !scanner.Scan() {
		os.Exit(1)
	}
	i, _ := strconv.Atoi(scanner.Text())
	return i
}

func getString() string {
	if !scanner.Scan() {
		os.Exit(1)
	}
	return scanner.Text()
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	sudoku := make([][]byte, 9)

	ini := func () int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	ins := func () []byte {
		sc.Scan()
		return sc.Bytes()
	}

	for t := ini(); t > 0 ; t-- {
		for i := 0; i < 9; i++ {
			sudoku[i] = ins()
		}

		sudoku[0][0] = sudoku[0][1]
		sudoku[1][3] = sudoku[1][4]
		sudoku[2][6] = sudoku[2][7]

		sudoku[3][1] = sudoku[3][2]
		sudoku[4][4] = sudoku[4][5]
		sudoku[5][7] = sudoku[5][8]

		sudoku[6][2] = sudoku[6][1]
		sudoku[7][5] = sudoku[7][4]
		sudoku[8][8] = sudoku[8][7]

		for i := range sudoku {
			fmt.Println(string(sudoku[i]))
		}
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1335/D
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	S    [][]rune
	memo [][2]int
)

func main() {
	memo = [][2]int{
		[2]int{0, 0}, [2]int{1, 3}, [2]int{2, 6},
		[2]int{3, 1}, [2]int{4, 4}, [2]int{5, 7},
		[2]int{6, 2}, [2]int{7, 5}, [2]int{8, 8},
	}

	t = ReadInt()
	for i := 0; i < t; i++ {
		S = [][]rune{}
		for j := 0; j < 9; j++ {
			row := ReadRuneSlice()
			S = append(S, row)
		}

		solve()
	}
}

func solve() {
	for _, c := range memo {
		i, j := c[0], c[1]
		if S[i][j] == '9' {
			S[i][j] = rune(1 + '0')
		} else {
			S[i][j]++
		}
	}

	for i := 0; i < 9; i++ {
		fmt.Println(string(S[i]))
	}
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

func main() {
	proj := make([][]int, 9)
	for i := range proj {
		proj[i] = []int{i, ((3 * i) + (i / 3)) % 9}
	}

	var truncator string
	if runtime.GOOS == "windows" {
		truncator = "\r\n"
	} else {
		truncator = "\n"
	}

	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimSuffix(text, truncator)
	testcase, _ := strconv.ParseInt(text, 10, 64)

	output := make([]string, testcase)
	var i int64
	sudoku := make([][]byte, 9)
	for i := range sudoku {
		sudoku[i] = make([]byte, 9)
	}

	for i = 0; i < testcase; i++ {
		for j := range sudoku {
			text, _ = reader.ReadString('\n')
			text = strings.TrimSuffix(text, truncator)
			inputSlice := []byte(text)
			copy(sudoku[j], inputSlice)
		}
		for _, v := range proj {
			sudoku[v[0]][v[1]] = next(sudoku[v[0]][v[1]])
		}
		output[i] = printsd(sudoku)
	}

	result := strings.Join(output, "\n")
	fmt.Printf(result)
	fmt.Printf("\n")
}

func next(a byte) byte {
	if a == '9' {
		a = '1'
		return a
	}
	a++
	return a
}

func printsd(a [][]byte) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = string(v)
	}
	c := strings.Join(b, "\n")
	return c
}

// Author: sighduck
// URL: https://codeforces.com/contest/1335/problem/D

package main

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

func Solve(sudoku [][]rune) [][]rune {
	for i := 0; i < 9; i++ {
		for j := 0; j < 9; j++ {
			if sudoku[i][j] == '1' {
				sudoku[i][j] = '2'
			}
		}
	}
	return sudoku
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		sudoku := make([][]rune, 9)
		for i := 0; i < 9; i++ {
			var row string
			fmt.Fscanf(reader, "%s\n", &row)
			sudoku[i] = []rune(row)
		}
		ans := Solve(sudoku)
		for _, row := range ans {
			fmt.Fprintf(writer, "%s\n", string(row))
		}
	}
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		board := [][]rune{}
		for i := 0; i < 9; i++ {
			row := reader.NextString()
			board = append(board, []rune(row))
		}
		anti(board)
        //check(board)
		for _, row := range board {
			writer.Printf("%s\n", string(row))
		}
	}
}

func anti(b [][]rune) {
    for _, p := range [][2]int{
        {0, 0},
        {1, 3},
        {2, 6},
        {3, 1},
        {4, 4},
        {5, 7},
        {6, 2},
        {7, 5},
        {8, 8},
    }{
        b[p[0]][p[1]] += 1
        if b[p[0]][p[1]] > '9' {
            b[p[0]][p[1]] -= 9
        }
    }
}

func check(b [][]rune) {
	for i := 0; i < 9; i++ {
		m := map[rune]int{}
		for j := 0; j < 9; j++ {
			m[b[i][j]]++
		}
		writer.Printf("%d\n", len(m)) // should be 8
	}
	for i := 0; i < 9; i++ {
		m := map[rune]int{}
		for j := 0; j < 9; j++ {
			m[b[j][i]]++
		}
		writer.Printf("%d\n", len(m)) // should be 8
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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 scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

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

func exec() {
	field := make([][]int, 9)
	for i := 0; i < 9; i++ {
		field[i] = make([]int, 9)
		str, err := reader.ReadString('\n')
		if err != nil {
			fmt.Println(err.Error())
			panic(err)
		}
		str = strings.TrimRight(str, "\n\r")
		for j, s := range []byte(str) {
			if j != i {
				printf("%s", string(s))
				continue
			}
			num, err := strconv.ParseInt(string(s), 10, 64)
			if err != nil {
				fmt.Println(err.Error())
				panic(err)
			}
			num -= 9
			if num == 0 {
				num = 1
			}
			printf("%d", int(math.Abs(float64(num))))
		}
		printf("\n")
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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 scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

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

func exec() {
	field := make([][]int, 9)
	for i := 0; i < 9; i++ {
		field[i] = make([]int, 9)
		str, err := reader.ReadString('\n')
		if err != nil {
			fmt.Println(err.Error())
			panic(err)
		}
		str = strings.TrimRight(str, "\n\r")
		for j, s := range []byte(str) {
			if j != i {
				printf("%s", string(s))
				continue
			}
			num, err := strconv.ParseInt(string(s), 10, 64)
			if err != nil {
				fmt.Println(err.Error())
				panic(err)
			}
			num -= 9
			if num == 0 {
				num = 1
			}
			printf("%d", int(math.Abs(float64(num-9))))
		}
		printf("\n")
	}
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	sudoku := make([][]byte, 9)

	ini := func () int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	ins := func () []byte {
		sc.Scan()
		return sc.Bytes()
	}

	for t := ini(); t > 0 ; t-- {
		for i := 0; i < 9; i++ {
			sudoku[i] = ins()
		}

		sudoku[0][0] = sudoku[0][1]
		sudoku[1][3] = sudoku[1][4]
		sudoku[2][5] = sudoku[2][6]

		sudoku[3][1] = sudoku[3][2]
		sudoku[4][4] = sudoku[4][5]
		sudoku[5][7] = sudoku[5][8]

		sudoku[6][2] = sudoku[6][1]
		sudoku[7][5] = sudoku[7][4]
		sudoku[8][8] = sudoku[8][7]

		for i := range sudoku {
			fmt.Println(string(sudoku[i]))
		}
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1335/D
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	S [][]rune
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		S = [][]rune{}
		for j := 0; j < 9; j++ {
			row := ReadRuneSlice()
			S = append(S, row)
		}

		solve()
	}
}

func solve() {
	for i := 0; i < 9; i++ {
		j := i
		if S[i][j] == '9' {
			S[i][j] = rune(1 + '0')
		} else {
			S[i][j]++
		}
	}

	for i := 0; i < 9; i++ {
		fmt.Println(string(S[i]))
	}
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		board := [][]rune{}
		for i := 0; i < 9; i++ {
			row := reader.NextString()
			board = append(board, []rune(row))
		}
		sol(board)
        //check(board)
		for _, row := range board {
			writer.Printf("%s\n", string(row))
		}
	}
}

func sol(b [][]rune) {
	b[0][0], b[1][3], b[2][6],
		b[3][1], b[4][4], b[5][7],
		b[6][2], b[7][5], b[8][8] = b[1][3], b[2][6],
		b[3][1], b[4][4], b[5][7],
		b[6][2], b[7][5], b[8][8], b[0][0]
}

func check(b [][]rune) {
    for i := 0; i < 9; i++ {
        m := map[rune]int{}
        for j := 0; j < 9; j++ {
            m[b[i][j]]++
        }
        writer.Printf("%d\n", len(m)) // should be 8
    }
    for i := 0; i < 9; i++ {
        m := map[rune]int{}
        for j := 0; j < 9; j++ {
            m[b[j][i]]++
        }
        writer.Printf("%d\n", len(m)) // should be 8
    }
}


You have a large rectangular board which is divided into $$$n \times m$$$ cells (the board has $$$n$$$ rows and $$$m$$$ columns). Each cell is either white or black.You paint each white cell either red or blue. Obviously, the number of different ways to paint them is $$$2^w$$$, where $$$w$$$ is the number of white cells.After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules:  each domino covers two adjacent cells;  each cell is covered by at most one domino;  if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells;  if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells. Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all $$$2^w$$$ possible ways to paint it. Since it can be huge, print it modulo $$$998\,244\,353$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 3 \cdot 10^5$$$; $$$nm \le 3 \cdot 10^5$$$) — the number of rows and columns, respectively. Then $$$n$$$ lines follow, each line contains a string of $$$m$$$ characters. The $$$j$$$-th character in the $$$i$$$-th string is * if the $$$j$$$-th cell in the $$$i$$$-th row is black; otherwise, that character is o.

Print one integer — the sum of values of the board over all $$$2^w$$$ possible ways to paint it, taken modulo $$$998\,244\,353$$$.

package main
import (
	"bufio"
	."fmt"
	"os"
	."strings"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	const P, M = 998244353, 3e5 + 1
	f := [M]int64{0, 0, 1}
	for i := 3; i < M; i++ {
		f[i] = ((3*f[i-1]-4*f[i-3])%P+P)%P
	}
	p := [M]int64{1}
	for i := 1; i < M; i++ {
		p[i] = p[i-1]*2%P
	}
	var n, m, w int
	Fscan(in, &n, &m)
	a := make([]string, n)
	for i := range a {
		Fscan(in, &a[i])
		w += Count(a[i], "o")
	}
	c := func(s string) (S int64) {
		for _, s := range Split(s, "*") {
			S = (S + f[len(s)]*p[w-len(s)]) % P
		}
		return
	}
	S := int64(0)
	for _, r := range a {
		S += c(r)
	}
	for j := range a[0] {
		s := []byte{}
		for _, r := range a {
			s = append(s, r[j])
		}
		S += c(string(s))
	}
	Print(S % P)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	const P, M = 998244353, 3e5
	dp := [M + 1]int64{0, 0, 1}
	for i := 3; i <= M; i++ {
		dp[i] = ((3*dp[i-1]-4*dp[i-3])%P + P) % P
	}
	p2 := [M + 1]int64{1}
	for i := 1; i <= M; i++ {
		p2[i] = p2[i-1] << 1 % P
	}

	var n, m, w int
	Fscan(in, &n, &m)
	a := make([][]byte, n)
	for i := range a {
		Fscan(in, &a[i])
		w += bytes.Count(a[i], []byte{'o'})
	}
	f := func(s []byte) (S int64) {
		for i, n := 0, len(s); i < n; {
			if s[i] == '*' {
				i++
				continue
			}
			j := i
			for ; i < n && s[i] == 'o'; i++ {
			}
			S = (S + dp[i-j]*p2[w-i+j]) % P
		}
		return
	}
	S := int64(0)
	for _, r := range a {
		S += f(r)
	}
	for j := range a[0] {
		s := []byte{}
		for _, r := range a {
			s = append(s, r[j])
		}
		S += f(s)
	}
	Print(S % P)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod = 998244353
	const mx int = 3e5
	dp := [mx + 1]int64{0, 0, 1}
	for i := 3; i <= mx; i++ {
		dp[i] = ((3*dp[i-1]-4*dp[i-3])%mod + mod) % mod
	}
	p2 := [mx + 1]int64{1}
	for i := 1; i <= mx; i++ {
		p2[i] = p2[i-1] << 1 % mod
	}

	var n, m, cw int
	Fscan(in, &n, &m)
	a := make([][]byte, n)
	for i := range a {
		Fscan(in, &a[i])
		cw += bytes.Count(a[i], []byte{'o'})
	}
	f := func(s []byte) (res int64) {
		for i, n := 0, len(s); i < n; {
			if s[i] == '*' {
				i++
				continue
			}
			st := i
			for ; i < n && s[i] == 'o'; i++ {
			}
			res = (res + dp[i-st]*p2[cw-(i-st)]) % mod
		}
		return
	}
	ans := int64(0)
	for _, s := range a {
		ans += f(s)
	}
	for j := range a[0] {
		s := make([]byte, 0, n)
		for _, r := range a {
			s = append(s, r[j])
		}
		ans += f(s)
	}
	Fprint(out, ans%mod)
}

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

package main
import (
	"bufio"
	."fmt"
	"os"
	."strings"
)
func main() {
	in := bufio.NewReader(os.Stdin)
	const P, M = 998244353, 3e5 + 1
	f := [M]int64{0, 0, 1}
	for i := 3; i < M; i++ {
		f[i] = ((3*f[i-1]-4*f[i-3])%P+P)%P
	}
	p := [M]int64{1}
	for i := 1; i < M; i++ {
		p[i] = p[i-1]*2%P
	}
	var n, m, w int
	Fscan(in, &n, &m)
	a := make([]string, n)
	for i := range a {
		Fscan(in, &a[i])
		w += Count(a[i], "o")
	}
	c := func(s string) (S int64) {
		for _, s := range Split(s, "*") {
			S = (S + f[len(s)]*p[w-len(s)]) % P
		}
		return
	}
	S := int64(0)
	for _, r := range a {
		S += c(r)
	}
	for j := range a[0] {
		s := []byte{}
		for _, r := range a {
			s = append(s, r[j])
		}
		S += c(string(s))
	}
	Print(S % P)
}

package main
import (
	"bufio"
	."fmt"
	"os"
	."strings"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	const P, M = 998244353, 3e5+1
	f := [M]int64{0, 0, 1}
	for i := 3; i < M; i++ {
		f[i] = 3*f[i-1]-4*f[i-3]
	}
	p := [M]int64{1}
	for i := 1; i < M; i++ {
		p[i] = p[i-1]*2%P
	}
	var n, m, w int
	Fscan(in, &n, &m)
	a := make([]string, n)
	for i := range a {
		Fscan(in, &a[i])
		w += Count(a[i], "o")
	}
	c := func(s string) (S int64) {
		for _, s := range Split(s, "*") {
			S = (S+f[len(s)]*p[w-len(s)])%P
		}
		return
	}
	S := int64(0)
	for _, r := range a {
		S += c(r)
	}
	for j := range a[0] {
		s := []byte{}
		for _, r := range a {
			s = append(s, r[j])
		}
		S += c(string(s))
	}
	Print((S%P+P)%P)
}