package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		n, _, x, y := s.NextInt(), s.NextInt(), s.NextInt(), s.NextInt()

		if y > 2*x {
			y = 2 * x
		}

		var total int
		var have bool
		for j := 0; j < n; j++ {
			have = false
			a := s.NextString()
			for _, c := range a {
				if c == '.' {
					if have {
						total += y
						have = false
					} else {
						have = true
					}
				} else {
					if have {
						total += x
					}
					have = false
				}
			}

			if have {
				total += x
			}
		}

		fmt.Println(total)
	}
}

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

package main

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

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		line := readNNums(reader, 4)
		n, m, x, y := line[0], line[1], line[2], line[3]
		B := make([][]byte, n)
		for i := 0; i < n; i++ {
			B[i], _ = reader.ReadBytes('\n')
		}
		fmt.Println(solve(n, m, B, x, y))
	}
}

func solve(n, m int, board [][]byte, x, y int) int64 {
	// row independent with each other
	X, Y := int64(x), int64(y)
	find := func(r int) int64 {
		// 前两个cell的cost
		var A, B int64

		for j := 0; j < m; j++ {
			if board[r][j] == '*' {
				A = B
				continue
			}
			if j == 0 || board[r][j-1] == '*' {
				// 只能使用x
				A, B = B, B+X
				continue
			}
			//也能使用y
			A, B = B, min(A+Y, B+X)
		}
		return B
	}

	var res int64

	for i := 0; i < n; i++ {
		res += find(i)
	}

	return res
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		n, m, x, y := 0, 0, 0, 0
		fmt.Fscanf(in, "%d %d %d %d\n", &n, &m, &x, &y)
		if y > 2*x {
			y = 2 * x
		}
		ans := 0
		s := ""
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%s\n", &s)
			cur := 0
			for j := 0; j < len(s); j++ {
				if s[j] == '*' {
					ans += cur/2*y + cur%2*x
					cur = 0
				} else {
					cur++
				}
			}
			ans += cur/2*y + cur%2*x
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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
}

// https://codeforces.com/contest/1358/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n, m, x,y int
	fmt.Fscan(input, &n, &m, &x, &y)
	sc := make([]int, 0)
	for i := 0; i < n; i++ {
	  var s string
	  fmt.Fscan(input, &s)
	  cc := 0
	  for j := 0; j < len(s); j++ {
	    if s[j] == '.' {
	      cc++
	      continue
	    }
	    if cc > 0 {
		sc = append(sc, cc)
	    }
	    cc = 0
	  }
	  if cc > 0 {
		sc = append(sc, cc)
	  }
	}
	//fmt.Println(x,y, sc)
	ans := 0
	for i := 0; i < len(sc); i++ {
	  ans += min(((sc[i]/2)*2)*x, (sc[i]/2) * y)
	  if sc[i] % 2 > 0 {
	    ans+=x
	  }
	}

	fmt.Println(ans)

}

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

package main

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n, m, x, y := reader.NextInt(), reader.NextInt(), reader.NextInt(),reader.NextInt()
		aa := make([][]string, n)
		for i:=range aa {
			aa[i]=make([]string,m)
		}
		for i:=0;i<len(aa);i++{
			input:=reader.NextString()
			inputarr:=strings.Split(input,"")
			for j:=0;j<len(aa[0]);j++{
				aa[i][j]=inputarr[j]
			}
		}
		// for i := 0; i < len(aa); i++ {
		// 	aa[i] = reader.NextInt64()
		// }
		writer.Printf("%d\n", sol(n,m,x,y,aa))
	}
}

func sol(n,m,x,y int, arr [][]string) int {
	// if m==0 {
	// 	return 0;
	// }
	dots:=0
	pairs:=0
	for i:=0;i<len(arr);i++ {
		for j:=0;j<len(arr[0]);j++{
			if(arr[i][j]=="*"){
				continue;
			}
			if(arr[i][j]=="."){
				if j!=len(arr[0])-1 && arr[i][j+1]=="."{
					pairs++
					arr[i][j]="-"
					arr[i][j+1]="-"
				}else{
					dots++
					arr[i][j]="-"
				}
			}
		}
	}
	if(y>=2*x){
		return x*dots+ 2*pairs*x
	}
	return dots*x + pairs*y

}

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

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()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
)

func main() {
	var t, m, n, x, y, ans, single, double int
	var tile string
	fmt.Scanf("%d\n", &t)

	for j := 0; j < t; j++ {
		fmt.Scanf("%d %d %d %d\n", &n, &m, &x, &y)
		single = 0
		double = 0
		for i := 0; i < n; i++ {
			fmt.Scanf("%s\n", &tile)
			var prev byte
			for k := 0; k < m; k++ {
				if tile[k] == '.' {
					if prev == '.' {
						single--
						double++
						prev = '*'
					} else {
						single++
						prev = '.'
					}
				} else {
					prev = '*'
				}
			}
		}
		if x*2 <= y {
			ans = x*single + 2*x*double
		} else {
			ans = x*single + y*double
		}
		fmt.Println(ans)
	}
}

/*
URL:
https://codeforces.com/contest/1359/problem/B
*/

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

	n, m, x, y int64
	S          [][]rune
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m, x, y = ReadInt64_4()
		S = [][]rune{}
		for j := int64(0); j < n; j++ {
			row := ReadRuneSlice()
			S = append(S, row)
		}

		solve()
	}
}

func solve() {
	if 2*x <= y {
		num := int64(0)
		for i := int64(0); i < n; i++ {
			for j := int64(0); j < m; j++ {
				if S[i][j] == '.' {
					num++
				}
			}
		}

		fmt.Println(num * x)
		return
	}

	ans := int64(0)
	for i := int64(0); i < n; i++ {
		comp, cnts := RunLengthEncoding(S[i])
		for j := 0; j < len(comp); j++ {
			if comp[j] == '.' {
				num := int64(cnts[j])
				c := num / 2

				ans += y * c
				if num%2 == 1 {
					ans += x
				}
			}
		}
	}
	fmt.Println(ans)
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []rune) ([]rune, []int) {
	runes := []rune{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []rune, L []int) []rune {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []rune{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

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

/*********** 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"
)

var nTest, n, m, x, y int
var a [100][1000]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &nTest)

	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n, &m, &x, &y)
		fmt.Fscanln(in)
		cntDot := 0

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				fmt.Fscanf(in, "%c", &a[i][j])
				if a[i][j] == '.' {
					cntDot++
				}
			}
			fmt.Fscanln(in)
		}

		if 2*x <= y {
			fmt.Fprintln(out, x*cntDot)
			continue
		}

		cnt1x2 := 0
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if a[i][j] == '.' && j < m-1 && a[i][j+1] == '.' {
					a[i][j] = '*'
					a[i][j+1] = '*'
					cnt1x2++
				}
			}
		}
		fmt.Fprintln(out, x*(cntDot-cnt1x2*2)+y*cnt1x2)
	}
	out.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var T, n, m, x, y int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &x, &y)
		if y > 2*x {
			y = 2 * x
		}
		ans := 0
		for ; n > 0; n-- {
			Fscan(in, &s)
			for _, s := range strings.Split(s, "*") {
				if s != "" {
					ans += len(s)/2*y + len(s)&1*x
				}
			}
		}
		Println(ans)
	}
}

package main

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

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%v\n", &t)
	for now := 0; now < t; now++ {
		var n, m, x, y int
		fmt.Fscanf(in, "%v %v %v %v\n", &n, &m, &x, &y)
		var cc, c int
		for i := 0;i < n;i++ {
			var s string
			fmt.Fscanf(in, "%v\n", &s)
			var l int
			for j := 0;j < m;j++ {
				if s[j] == '.' {
					if l == 1 {
						l = 0
						cc++
					} else {
						l = 1
					}
				} else {
					if l == 1 {
						c++
					}
					l = 0
				}
			}
			if l == 1 {
				c++
			}
		}
		fmt.Fprintln(out, min(x * (2 * cc + c), y * cc + c * x))
	}
	return
}

package main

import "fmt"
import "bufio"
import "os"

func main() {
	buf := bufio.NewReader(os.Stdin)
	var t int

	fmt.Fscanf(buf, "%d\n", &t)

	var n, m, x, y int

	for i:=0; i< t; i++ {
		fmt.Fscanf(buf, "%d", &n)
		fmt.Fscanf(buf, "%d", &m)
		fmt.Fscanf(buf, "%d", &x)
		fmt.Fscanf(buf, "%d\n", &y)

		var s string
		sum := 0
		for j := 0; j< n; j++ {
			fmt.Fscanf(buf, "%s\n", &s)
			sum += getMinCost(s, x, y)
		}
		fmt.Println(sum)
	}
}

func getMinCost(s string, x, y int) int {

	cost := 0

	for i:=0; i<len(s); i++ {
		if i+1 <= len(s) -1 && s[i] == '.' && s[i+1] == '.' {
			c := min(x*2, y);
			cost += c;
			i++;
		} else if s[i]=='.' {
			cost += x;
		}
	}

	return cost
}

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

package main

import (
	"fmt"
	"bufio"
	"os"
)
var fin *bufio.Reader = bufio.NewReader(os.Stdin)
var fout *bufio.Writer = bufio.NewWriter(os.Stdout)
func max(a int, b int) int { if(a > b) { return a } else { return b }}
func main() {
	defer fout.Flush()
	var asdf int
	fmt.Fscan(fin, &asdf)
	for ; asdf > 0; asdf-- {
		var n,m,x,y int
		fmt.Fscan(fin, &n, &m, &x, &y)
		if 2*x < y {
			y = 2*x
		}
		ans := 0
		for ; n > 0; n-- {
			var s string
			fmt.Fscan(fin, &s)
			for i := 0; i < m; i++ {
				if s[i] == '*' {
					continue
				}
				if i != m-1 && s[i+1] == '.' {
					ans += y
					i++
				} else {
					ans += x
				}
			}
		}
		fmt.Fprintln(fout, ans)
	}
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n, m, x, y int
		fmt.Fscan(r, &n, &m, &x, &y)

		var ans int
		for i := 0; i < n; i++ {
			var s string
			fmt.Fscan(r, &s)
			var j int
			for j < m {
				if s[j] == '.' {
					if j+1 < m && s[j+1] == '.' {
						if x*2 > y {
							ans += y
						} else {
							ans += x * 2
						}
						j += 2
					} else {
						ans += x
						j++
					}
				} else {
					j++
				}
			}
		}

		fmt.Fprintln(w, ans)
	}
}

package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 0
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for i := 0; i < t; i++ {
		testcase(scanner, writer)
	}
}

func testcase(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	x := getNextInt(scanner)
	y := getNextInt(scanner)
	var ans int
	for i := 0; i < n; i++ {
		s := getNextString(scanner)
		for j := 0; j < m; j++ {
			if s[j] == '*' {
				continue
			}
			if strings.Index(s[j:], "..") == 0 {
				ans += minint(x<<1, y)
				j++
				continue
			}
			ans += x
		}
	}
	fmt.Fprintln(writer, ans)
}

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

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"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 {
	Int64() int64
	UInt64() uint64
	String() 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) Int64() 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) UInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
)

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

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		n := reader.Int64()
		_ = reader.Int64()
		x := reader.Int64()
		y := reader.Int64()
		a := make([][]byte, n)
		for i := range a {
			a[i] = []byte(reader.String())
		}
		writer.Printf("%d\n", sol(a, x, y))
	}
}

func sol(a [][]byte, x, y int64) int64 {
	// placing a 1x1 tile is more price efficient
	// so just count all the dots
	if x*2 <= y {
		ret := int64(0)
		for i := range a {
			for j := range a[i] {
				if a[i][j] == '.' {
					ret += x
				}
			}
		}
		return ret
	}

	// placing a 1x2 tile is more price efficient
	ret := int64(0)
	for i := range a {
		for j := range a[i] {
			if a[i][j] == '.' {
				// try horizontal 1x2 tile
				if j < len(a[i])-1 && a[i][j+1] == '.' {
					ret += y
					a[i][j] = '*'
					a[i][j+1] = '*'
				} else {
					ret += x
					a[i][j] = '*'
				}
			}
		}
	}
	return ret
}

// https://codeforces.com/contest/1358/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n, m, x,y int
	fmt.Fscan(input, &n, &m, &x, &y)
	sc := make([]int, n)
	for i := 0; i < n; i++ {
	  var s string
	  fmt.Fscan(input, &s)
	  for j := 0; j < len(s); j++ {
	    if s[j] == '.' {
	      sc[i]++
	    }
	  }
	}
	//fmt.Println(x,y, sc)
	ans := 0
	for i := 0; i < n; i++ {
	  ans += min(((sc[i]>>1)<<1)*x, sc[i]/2 * y)
	  if sc[i] % 2 > 0 {
	    ans+=x
	  }
	}

	fmt.Println(ans)

}

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

// https://codeforces.com/contest/1358/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n, m, x,y int
	fmt.Fscan(input, &n, &m, &x, &y)
	sc := make([]int, n)
	for i := 0; i < n; i++ {
	  var s string
	  fmt.Fscan(input, &s)
	  for j := 0; j < len(s); j++ {
	    if s[j] == '.' {
	      sc[i]++
	    }
	  }
	}
	//fmt.Println(x,y, sc)
	ans := 0
	for i := 0; i < n; i++ {
	  ans += min(sc[i]*x, sc[i]/2 * y)
	  if sc[i] % 2 > 0 {
	    ans+=x
	  }
	}

	fmt.Println(ans)

}

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

// https://codeforces.com/contest/1358/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n, m, x,y int
	fmt.Fscan(input, &n, &m, &x, &y)
	sc := make([]int, n)
	for i := 0; i < n; i++ {
	  var s string
	  fmt.Fscan(input, &s)
	  for j := 0; j < len(s); j++ {
	    if s[j] == '.' {
	      sc[i]++
	    }
	  }
	}
	//fmt.Println(x,y, sc)
	ans := 0
	for i := 0; i < n; i++ {
	  ans += min(sc[i]/2*x, sc[i]/2 * y)
	  if sc[i] % 2 > 0 {
	    ans+=x
	  }
	}

	fmt.Println(ans)

}

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

package main

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

var nTest, n, m, x, y int
var a [100][1000]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &nTest)

	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &n, &m, &x, &y)
		fmt.Fscanln(in)
		cntDot := 0

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				fmt.Fscanf(in, "%c", &a[i][j])
				if a[i][j] == '.' {
					cntDot++
				}
			}
			fmt.Fscanln(in)
		}

		if 2*x <= y {
			fmt.Fprintln(out, x*cntDot)
			out.Flush()
			return
		}

		cnt1x2 := 0
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if a[i][j] == '.' && j < m-1 && a[i][j+1] == '.' {
					a[i][j] = '*'
					a[i][j+1] = '*'
					cnt1x2++
				}
			}
		}
		fmt.Fprintln(out, x*(cntDot-cnt1x2*2)+y*cnt1x2)
	}
	out.Flush()
}


package main

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

/*
5
3 4
0 0 0 0
0 1 0 0
0 0 0 0
2 2
3 0
0 0
2 2
0 0
0 0
2 3
0 0 0
0 4 0
4 4
0 0 0 0
0 2 0 1
0 0 0 0
0 0 0 0

YES
0 0 0 0
0 1 1 0
0 0 0 0
NO
YES
0 0
0 0
NO
YES
0 1 0 0
1 4 2 1
0 2 0 0
1 3 1 0
*/

func NeighborGrid(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, rows, columns, target int64
	var result [][]int64

	for Fscan(in, &T); T > int64(0); T-- {
		Fscan(in, &rows)
		Fscan(in, &columns)
		result = make([][]int64, rows)
		for i := int64(0); i < rows; i++ {
			result[i] = make([]int64, columns)
		}

		for i := int64(0); i < rows; i++ {
			for j := int64(0); j < columns; j++ {
				Fscan(in, &target)
				result[i][j] = target
			}
		}

		for i := int64(0); i < rows; i++ {
			for j := int64(0); j < columns; j++ {
				if i == 0 || i == rows-1 || j == 0 || j == columns-1 {
					if (i == 0 && j == 0) || (i == rows-1 && j == 0) || (i == 0 && j == columns-1) || (i == rows-1 && j == columns-1) {
						if result[i][j] > 2 {
							Fprintln(out, "No")
							goto BREAK
						} else {
							result[i][j] = 2
						}
					} else {
						if result[i][j] > 3 {
							Fprintln(out, "NO")
							goto BREAK
						} else {
							result[i][j] = 3
						}
					}
				} else {
					if result[i][j] > 4 {
						Fprintln(out, "NO")
						goto BREAK
					} else {
						result[i][j] = 4
					}
				}
			}
		}

		Fprintln(out, "YES")
		for i := int64(0); i < rows; i++ {
			for j := int64(0); j < columns; j++ {
				Fprintf(out, "%d ", result[i][j])
			}
			Fprintf(out, "\n")
		}

	BREAK:
	}

}

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

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

var dx = [4]int{0, 0, -1, 1}
var dy = [4]int{-1, 1, 0, 0}

func main() {
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	if false {
		file, err := os.Open("b.in")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file, 8192)
	} else {
		in = bufio.NewReaderSize(os.Stdin, 8192)
	}

	t := nextInt()
outer:
	for ; t > 0; t-- {
		n, m := nextInt(), nextInt()
		arr := make([][]int, n)
		for i := 0; i < n; i++ {
			arr[i] = make([]int, m)
			for j := 0; j < m; j++ {
				arr[i][j] = nextInt()
			}
		}
		for i, u := range arr {
			for j, v := range u {
				count := 0

				for k := 0; k < 4; k++ {
					nx, ny := i+dx[k], j+dy[k]
					if nx < 0 || ny < 0 || nx >= n || ny >= m {
						continue
					}
					count++
				}
				if count < v {
					printf("NO\n")
					continue outer
				}
				arr[i][j] = count
			}
		}

		printf("YES\n")
		for _, u := range arr {
			for _, v := range u {
				printf("%d ", v)
			}
			printf("\n")
		}
	}
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		G := make([][]int, n)
		for i := 0; i < n; i++ {
			G[i] = readNNums(reader, m)
		}
		good := solve(n, m, G)
		if good {
			buf.WriteString("YES\n")
			for i := 0; i < n; i++ {
				for j := 0; j < m; j++ {
					if j < m-1 {
						buf.WriteString(fmt.Sprintf("%d ", G[i][j]))
					} else {
						buf.WriteString(fmt.Sprintf("%d\n", G[i][j]))
					}
				}
			}
		} else {
			buf.WriteString("NO\n")
		}
	}
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n, m int, G [][]int) bool {
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			var cnt int
			if i > 0 {
				cnt++
			}
			if i < n-1 {
				cnt++
			}
			if j > 0 {
				cnt++
			}
			if j < m-1 {
				cnt++
			}
			if G[i][j] > cnt {
				return false
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			var cnt int
			if i > 0 {
				cnt++
			}
			if i < n-1 {
				cnt++
			}
			if j > 0 {
				cnt++
			}
			if j < m-1 {
				cnt++
			}
			G[i][j] = cnt
		}
	}
	return true
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &m)
		possible := true
		for j := 1; j <= n; j++ {
			for k := 1; k <= m; k++ {
				var a int
				fmt.Fscan(in, &a)
				if a > 4 {
					possible = false
				} else if ((j == 1 && k == 1) || (j == n && k == 1) || (j == 1 && k == m) || (j == n && k == m)) && a > 2 {
					possible = false
				} else if (j == 1 || k == 1 || j == n || k == m) && a > 3 {
					possible = false
				}
			}
		}
		if !possible {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			for j := 1; j <= n; j++ {
				for k := 1; k <= m; k++ {
					if (j == 1 && k == 1) || (j == n && k == 1) || (j == 1 && k == m) || (j == n && k == m) {
						fmt.Print(2, " ")
					} else if j == 1 || k == 1 || j == n || k == m {
						fmt.Print(3, " ")
					} else {
						fmt.Print(4, " ")
					}
				}
				fmt.Println()
			}
		}
	}
}

package main

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

func check(i, j, n, m int) int {
	cntNeighbors := 4
	// top .. bottom overflows
	if i-1 < 0 {
		cntNeighbors--
	} else if i+1 >= n {
		cntNeighbors--
	}
	// left .. right overflows
	if j-1 < 0 {
		cntNeighbors--
	} else if j+1 >= m {
		cntNeighbors--
	}
	return cntNeighbors
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, m := 0, 0
		good := true
		fmt.Fscan(in, &n, &m)
		grid := make([][]int, n)
		for i := 0; i < n; i++ {
			grid[i] = make([]int, m)
			for j := 0; j < m; j++ {
				a := 0
				fmt.Fscan(in, &a)
				// have already a wrong answer -> immediately leave after the new input consumption
				if !good {
					continue
				}
				cnt := check(i, j, n, m)
				if a <= cnt {
					grid[i][j] = cnt
				} else {
					good = false
				}
			}
		}
		if !good {
			fmt.Fprintln(out, "NO")
			continue
		}
		fmt.Fprintln(out, "YES")
		for i := 0; i < n; i++ {
			fmt.Fprintf(out, "%d", grid[i][0])
			for j := 1; j < m; j++ {
				fmt.Fprintf(out, " %d", grid[i][j])
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

func check(i, j, n, m int) int {
	cntNeighbors := 4
	// top .. bottom overflows
	if i-1 < 0 {
		cntNeighbors--
	} else if i+1 >= n {
		cntNeighbors--
	}
	// left .. right overflows
	if j-1 < 0 {
		cntNeighbors--
	} else if j+1 >= m {
		cntNeighbors--
	}
	return cntNeighbors
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, m := 0, 0
		// 'not good' grid flag
		fail := 0
		fmt.Fscan(in, &n, &m)
		grid := make([][]int, n)
		for i := 0; i < n; i++ {
			grid[i] = make([]int, m)
			for j := 0; j < m; j++ {
				a := 0
				fmt.Fscan(in, &a)
				cnt := check(i, j, n, m)
				if a <= cnt {
					grid[i][j] = cnt
				} else {
					fail |= 1
				}
			}
		}
		if fail == 1 {
			fmt.Fprintln(out, "NO")
			continue
		}
		fmt.Fprintln(out, "YES")
		for i := 0; i < n; i++ {
			fmt.Fprintf(out, "%d", grid[i][0])
			for j := 1; j < m; j++ {
				fmt.Fprintf(out, " %d", grid[i][j])
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

func check(i, j, n, m int) int {
	cntNeighbors := 4
	// top .. bottom overflows
	if i-1 < 0 {
		cntNeighbors--
	} else if i+1 >= n {
		cntNeighbors--
	}
	// left .. right overflows
	if j-1 < 0 {
		cntNeighbors--
	} else if j+1 >= m {
		cntNeighbors--
	}
	return cntNeighbors
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		n, m := 0, 0
		good := true
		fmt.Fscan(in, &n, &m)
		grid := make([][]int, n)
		// perform a full grid completion ( max value for each cell )
		for i := 0; i < n; i++ {
			grid[i] = make([]int, m)
			for j := 0; j < m; j++ {
				a := 0
				fmt.Fscan(in, &a)
				// have already a wrong answer
				// -> immediately leave after the new input consumption
				if !good {
					continue
				}
				cnt := check(i, j, n, m)
				if a <= cnt {
					grid[i][j] = cnt
				} else {
					good = false
				}
			}
		}
		if !good {
			fmt.Fprintln(out, "NO")
			continue
		}
		fmt.Fprintln(out, "YES")
		for i := 0; i < n; i++ {
			fmt.Fprintf(out, "%d", grid[i][0])
			for j := 1; j < m; j++ {
				fmt.Fprintf(out, " %d", grid[i][j])
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

var dx = [4]int{0, 0, -1, 1}
var dy = [4]int{-1, 1, 0, 0}

func main() {
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()
	if false {
		file, err := os.Open("b.in")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file, 8192)
	} else {
		in = bufio.NewReaderSize(os.Stdin, 8192)
	}

	t := nextInt()
outer:
	for ; t > 0; t-- {
		n, m := nextInt(), nextInt()
		arr := make([][]int, n)
		for i := 0; i < n; i++ {
			arr[i] = make([]int, m)
			for j := 0; j < m; j++ {
				arr[i][j] = nextInt()
			}
		}
		for i, u := range arr {
			for j, v := range u {
				if v == 0 {
					continue
				}
				count := 0
				for k := 0; k < 4; k++ {
					nx, ny := i+dx[k], j+dy[k]
					if nx < 0 || ny < 0 || nx >= n || ny >= m {
						continue
					}
					if arr[nx][ny] == 0 {
						count++
					}
				}

				if v > count {
					printf("NO\n")
					continue outer
				}
				arr[i][j] = count
			}
		}
		printf("YES\n")
		for _, u := range arr {
			for _, v := range u {
				printf("%d ", v)
			}
			printf("\n")
		}
	}
}

package main

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

/*
5
3 4
0 0 0 0
0 1 0 0
0 0 0 0
2 2
3 0
0 0
2 2
0 0
0 0
2 3
0 0 0
0 4 0
4 4
0 0 0 0
0 2 0 1
0 0 0 0
0 0 0 0

YES
0 0 0 0
0 1 1 0
0 0 0 0
NO
YES
0 0
0 0
NO
YES
0 1 0 0
1 4 2 1
0 2 0 0
1 3 1 0
*/

func NeighborGrid(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, rows, columns, target int64
	var result [][]int64

	for Fscan(in, &T); T > int64(0); T-- {
		Fscan(in, &rows)
		Fscan(in, &columns)
		result = make([][]int64, rows)
		for i := int64(0); i < rows; i++ {
			result[i] = make([]int64, columns)
		}

		for i := int64(0); i < rows; i++ {
			for j := int64(0); j < columns; j++ {
				Fscan(in, &target)
				result[i][j] = target
			}
		}

		for i := int64(0); i < rows; i++ {
			for j := int64(0); j < columns; j++ {
				if i == 0 || i == rows-1 || j == 0 || j == columns-1 {
					if (i == 0 && j == 0) || (i == rows-1 && j == 0) || (i == 0 && j == columns-1) || (i == rows-1 && j == columns-1) {
						if result[i][j] > 2 {
							Fprintln(out, "FALSE")
							goto BREAK
						} else {
							result[i][j] = 2
						}
					} else {
						if result[i][j] > 3 {
							Fprintln(out, "FALSE")
							goto BREAK
						} else {
							result[i][j] = 3
						}
					}
				} else {
					if result[i][j] > 4 {
						Fprintln(out, "FALSE")
						goto BREAK
					} else {
						result[i][j] = 4
					}
				}
			}
		}

		Fprintln(out, "YES")
		for i := int64(0); i < rows; i++ {
			for j := int64(0); j < columns; j++ {
				Fprintln(out, result[i][j])
			}
		}

	BREAK:
	}

}

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

package main

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

/*
5
3 4
0 0 0 0
0 1 0 0
0 0 0 0
2 2
3 0
0 0
2 2
0 0
0 0
2 3
0 0 0
0 4 0
4 4
0 0 0 0
0 2 0 1
0 0 0 0
0 0 0 0

YES
0 0 0 0
0 1 1 0
0 0 0 0
NO
YES
0 0
0 0
NO
YES
0 1 0 0
1 4 2 1
0 2 0 0
1 3 1 0
*/

func NeighborGrid(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, rows, columns, target int64
	var result [][]int64

	for Fscan(in, &T); T > int64(0); T-- {
		Fscan(in, &rows)
		Fscan(in, &columns)
		result = make([][]int64, rows)
		for i := int64(0); i < rows; i++ {
			result[i] = make([]int64, columns)
		}

		for i := int64(0); i < rows; i++ {
			for j := int64(0); j < columns; j++ {
				Fscan(in, &target)
				result[i][j] = target
			}
		}

		for i := int64(0); i < rows; i++ {
			for j := int64(0); j < columns; j++ {
				if i == 0 || i == rows-1 || j == 0 || j == columns-1 {
					if (i == 0 && j == 0) || (i == rows-1 && j == 0) || (i == 0 && j == columns-1) || (i == rows-1 && j == columns-1) {
						if result[i][j] > 2 {
							Fprintln(out, "No")
							goto BREAK
						} else {
							result[i][j] = 2
						}
					} else {
						if result[i][j] > 3 {
							Fprintln(out, "NO")
							goto BREAK
						} else {
							result[i][j] = 3
						}
					}
				} else {
					if result[i][j] > 4 {
						Fprintln(out, "NO")
						goto BREAK
					} else {
						result[i][j] = 4
					}
				}
			}
		}

		Fprintln(out, "YES")
		for i := int64(0); i < rows; i++ {
			Fprintln(out, result[i])
		}

	BREAK:
	}

}

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


/*
URL:
https://codeforces.com/problemset/problem/1155/C
*/

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 (
	n, m int
	X, P []int64
)

func main() {
	n, m = ReadInt2()
	X = ReadInt64Slice(n)
	P = ReadInt64Slice(m)

	g := int64(0)
	for i := 1; i < n; i++ {
		g = Gcd(g, X[i]-X[i-1])
	}

	p := -1
	for i := 0; i < m; i++ {
		if g%P[i] == 0 {
			p = i + 1
			break
		}
	}

	if p == -1 {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	fmt.Println(X[0], p)
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int64) int64 {
	if a < 0 || b < 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	if a == 0 {
		return b
	}
	if b == 0 {
		return a
	}

	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int64) int64 {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/*********** 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"
	"strconv"
)

func solve(j Jam) {
	n, m := j.Int(), j.Int()
	x := make([]uint64, n, n)
	periodGcd := uint64(0)
	for i := range x {
		x[i] = uint64(j.Int())
		if i > 0 {
			period := x[i] - x[i-1]
			if i == 1 {
				periodGcd = period
			} else {
				periodGcd = gcd(periodGcd, period)
			}
		}
	}
	for i := int64(1); i <= m; i++ {
		pi := uint64(j.Int())
		modulo := x[0] % pi
		if periodGcd%pi > 0 {
			continue
		}
		valid := true
		for _, xi := range x {
			if xi%pi != modulo {
				valid = false
				break
			}
		}
		if valid {
			j.P("YES\n%d %d\n", x[0], i)
			return
		}
	}
	j.P("NO\n")
}

func main() {
	jam, closeFunc := JamNew()
	defer closeFunc()
	solve(jam)
}

type Jam interface {
	Scanner() *bufio.Scanner
	Writer() *bufio.Writer
	Close()

	Str() string
	Int() int64
	Float() float64

	P(format string, values ...interface{})
	PF(format string, values ...interface{})
}

func JamNew() (Jam, func()) {
	if len(os.Args) > 1 {
		panic("running with input file path is not supported")
	}

	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)

	var writer = bufio.NewWriter(os.Stdout)
	jam := &jam{scanner, writer}
	return jam, jam.Close
}

type jam struct {
	sc *bufio.Scanner
	wr *bufio.Writer
}

func (j *jam) Close() {
	if err := j.wr.Flush(); err != nil {
		panic(err)
	}
}

func (j *jam) Scanner() *bufio.Scanner {
	return j.sc
}

func (j *jam) Writer() *bufio.Writer {
	return j.wr
}

func (j *jam) Str() string {
	if !j.sc.Scan() {
		panic("failed to scan next token")
	}

	return j.sc.Text()
}

func (j *jam) Int() int64 {
	if !j.sc.Scan() {
		panic("failed to scan next token")
	}

	res, err := strconv.ParseInt(j.sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}

	return res
}

func (j *jam) Float() float64 {
	j.sc.Scan()
	res, err := strconv.ParseFloat(j.sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (j *jam) P(format string, values ...interface{}) {
	_, err := fmt.Fprintf(j.wr, format, values...)
	if err != nil {
		panic(err)
	}
}

func (j *jam) PF(format string, values ...interface{}) {
	_, err := fmt.Fprintf(j.wr, format, values...)
	if err != nil {
		panic(err)
	}
	if err = j.wr.Flush(); err != nil {
		panic(err)
	}
}

func gcd(x, y uint64) uint64 {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func getGcd(a, b int64) int64 {
	for b > 0 {
		a, b = b, a%b
	}
	return a
}

func main() {
	defer writer.Flush() // STDOUT MUST BE FLUSHED MANUALLY!!!
	var n, m int64
	scan(&n, &m)
	evt, intr := make([]int64, n), make([]int64, m)

	for i := int64(0); i < n; i++ {
		scan(&evt[i])

		if i != 0 {
			evt[i] -= evt[0]
		}
	}

	for i := int64(0); i < m; i++ {
		scan(&intr[i])
	}

	// SOLVE
	yval := evt[0]
	evt[0] = 0
	gcd := int64(-1)

	for idx, val := range evt {
		if idx == 0 {
			continue
		}
		if idx == 1 {
			gcd = val
			continue
		}

		gcd = getGcd(gcd, val)

		if gcd == 1 {
			break
		}
	}

	// Find GCD (or a multiplier) in the pointers.

	for idx, val := range intr {
		if gcd%val == 0 {
			print("YES\n")
			printf("%d %d", yval, idx+1)
			return
		}
	}

	print("NO\n")
}


package main

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

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

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var niter int
	fmt.Fscan(scanner, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		var m int
		fmt.Fscan(scanner, &n, &m)
		res := int64(0)
		cor := make([]int, m)
		intervals := make([]int, 0)
		for i := 0; i < m; i++ {
			fmt.Fscan(scanner, &cor[i])
		}
		sort.Slice(cor, func(i, j int) bool { return cor[i] < cor[j] })
		for i := 1; i < m; i++ {
			intervals = append(intervals, cor[i]-cor[i-1]-1)
		}
		intervals = append(intervals, cor[0]+n-cor[len(cor)-1]-1)
		sort.Slice(intervals, func(i, j int) bool { return intervals[i] > intervals[j] })
		//fmt.Println("!!!", intervals, cor)
		day := 0
		for i := 0; i < len(intervals); i++ {
			tmp := 0
			if intervals[i]-day*2 != 1 {
				tmp = max(intervals[i]-1-day*2, 0)
				day += 2
			} else {
				tmp = 1
				day += 2
			}
			res += int64(tmp)
			if tmp <= 0 {
				break
			}
			//fmt.Println("!!!", intervals, day, res, "!!!", i)
		}
		fmt.Fprintln(writer, int64(n)-res)
	}
}

package main

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

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

func CF1704C(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, m int64
		fmt.Fscan(r, &n, &m)
		arr, ll := make([]int, m), make([]int, 0)
		for i := int64(0); i < m; i++ {
			fmt.Fscan(r, &arr[i])
		}
		sort.Ints(arr)
		for i := int64(0); i < m; i++ {
			if i == 0 {
				ll = append(ll, arr[i]+int(n)-arr[m-1]-1)
				continue
			}
			ll = append(ll, arr[i]-arr[i-1]-1)
		}
		sort.Sort(sort.Reverse(sort.IntSlice(ll)))

		day, ans := 0, 0
		for _, v := range ll {
			if v > day*2 {
				if v-1-day*2 >= 2 {
					ans += v - 1 - day*2
					day += 2
				} else {
					ans += 1
					day += 1
				}
			}
		}
		fmt.Fprintln(w, int(n)-ans)
	}

}

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

func max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

package main

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

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n, m int
		fmt.Fscan(r, &n, &m)
		a := make([]int, m)
		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(n, m, a)
		fmt.Fprintln(w, w1)
	}
}

func do(n, m int, a []int) int {
	sort.Ints(a)
	var b []int
	for i, v := range a {
		x := 0
		if i == 0 {
			x = n - a[m-1] + v - 1
		} else {
			x = v - a[i-1] - 1
		}
		if x > 0 {
			b = append(b, x)
		}
	}
	sort.Ints(b)
	var k int
	var x int
	for i := len(b) - 1; i >= 0; i-- {
		c := b[i] - 2*k
		if c <= 0 {
			break
		}
		if c <= 2 {
			x++
			break
		}
		k += 2
		x += c - 1
	}
	return n - x
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		aa := make([]int, m)
		for i := 0; i < m; i++ {
			fmt.Fscan(in, &aa[i])
		}

		sort.Ints(aa)
		bb := []int{n - aa[m-1] + aa[0] - 1}
		for i := 1; i < m; i++ {
			bb = append(bb, aa[i]-aa[i-1]-1)
		}
		sort.Slice(bb, func(i, j int) bool { return bb[i] > bb[j] })

		var d int
		var x int
		for _, v := range bb {
			v -= 2 * d
			if v <= 0 {
				break
			}
			if v == 1 {
				x++
			} else {
				x += v - 1
			}
			d += 2
		}
		fmt.Fprintln(out, n-x)
	}
}

package main

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

func solve() {
	n := get()
	m := get()
	a := geta1(m)

	sort.Ints(a)
	d := ints(m, 0)
	for i := 0; i+1 < m; i++ {
		d[i] = a[i+1] - a[i] - 1
	}
	d[m-1] = n - a[m-1] + a[0] - 1
	sort.Sort(sort.Reverse(sort.IntSlice(d)))

	count := 0
	for i, v := range d {
		start := 2 * i
		end := v - 2*i - 1
		result := end - start
		if result <= 0 {
			if result == 0 {
				count++
			}
			break
		}
		count += result
	}
	putln(n - count)
}

const (
	once       = false
	maxBufSize = 0 //10_000_000
	YES        = "YES"
	NO         = "NO"
)

var (
	splitFunc = bufio.ScanWords //bufio.SplitFunc(nil)
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	if splitFunc != nil {
		in.Split(splitFunc)
	}
	if maxBufSize > 0 {
		in.Buffer(make([]byte, maxBufSize), maxBufSize)
	}

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	for t := get(); t > 0; t-- {
		solve()
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func geta1(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get() - 1
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func get64a1(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64() - 1
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func line() {
	putc('\n')
}

func space() {
	putc(' ')
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts(YES)
	line()
}

func no() {
	puts(NO)
	line()
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

type IntTp interface {
	int | int64
}

type Tp interface {
	IntTp | float64
}

func abs[T IntTp](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func fabs(x float64) float64 {
	return math.Abs(x)
}

func max1[T Tp](x T, y T) T {
	if x > y {
		return x
	}
	return y
}

func max[T Tp](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = max1(r, x)
	}
	return r
}

func maxa[T Tp](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] <= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func min1[T Tp](x T, y T) T {
	if x < y {
		return x
	}
	return y
}

func min[T Tp](xs ...T) T {
	r := xs[0]
	for _, x := range xs[1:] {
		r = min1(r, x)
	}
	return r
}

func mina[T Tp](a []T) (i int, val T) {
	i, val = 0, a[0]
	for j := 1; j < len(a); j++ {
		if a[j] >= val {
			continue
		}
		i = j
		val = a[j]
	}
	return
}

func L(i int) int64 {
	return int64(i)
}

func F(i int) float64 {
	return float64(i)
}

func ints(n int, val int) (a []int) {
	a = make([]int, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func int64s(n int, val int64) (a []int64) {
	a = make([]int64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func floats(n int, val float64) (a []float64) {
	a = make([]float64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

const heapBase = 4

func children(i int) (int, int) {
	start := heapBase * i
	return start + 1, start + (1 + heapBase)
}

func parent(i int) int {
	return (i - 1) / heapBase
}

package main

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

func main() {
	var n, m int
	f := bufio.NewReader(os.Stdin)
	s, _ := f.ReadString('\n')
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	t, _ := strconv.ParseInt(s, 10, 32)
	for i := 0; i < int(t); i++ {
		s, _ = f.ReadString('\n')
		s = strings.ReplaceAll(s, "\n", "")
		s = strings.ReplaceAll(s, "\r", "")
		_, _ = fmt.Sscanf(s, "%d %d", &n, &m)
		s, _ = f.ReadString('\n')
		s = strings.ReplaceAll(s, "\r", "")
		s = strings.ReplaceAll(s, "\n", "")
		as := strings.SplitN(s, " ", m)
		arr := make([]int, len(as))
		if len(as) != m {
			panic("kek")
		}
		for k, a := range as {
			x, _ := strconv.ParseInt(a, 10, 64)
			arr[k] = int(x)
		}
		sort.Ints(arr)
		ranges := make([]int, 0, len(as))
		safe := 0
		for j := 0; j < m-1; j++ {
			ranges = append(ranges, arr[j+1]-arr[j]-1)
		}
		ranges = append(ranges, arr[0]-1+n-arr[len(arr)-1])
		sort.Ints(ranges)
		time := 0
		k := len(ranges) - 1
		for k >= 0 {
			if ranges[k] > time*2+1 {
				safe += ranges[k] - time*2 - 1
				time += 2
				k--
			} else if ranges[k] == time*2+1 {
				safe++
				k--
				time++
			} else {
				break
			}
		}
		fmt.Println(n - safe)
	}
}

package main

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

const cf = true

func solve() {
	var n, m int
	fmt.Fscan(in, &n, &m)
	arr := make([]int, m)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})
	packs := make([]int, 0, m+2)
	packs = append(packs, arr[0]-1+(n-arr[m-1]))
	for i := 1; i < m; i++ {
		packs = append(packs, arr[i]-arr[i-1]-1)
	}
	sort.Slice(packs, func(i, j int) bool {
		return packs[i] > packs[j]
	})
	sub, ans := 0, 0
	for i := range packs {
		toAdd := packs[i] - sub
		if toAdd != 1 {
			toAdd -= 1
		}
		sub += 4
		if toAdd <= 0 {
			break
		}
		ans += toAdd
	}
	fmt.Fprintln(out, n-ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	nums := make([]int, m)
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
		nums[i]--
	}
	sort.Ints(nums)
	intervals := make([]int, 0)
	for i:=1;i<len(nums);i++ {
		if nums[i] - nums[i-1] > 1 {
			intervals = append(intervals, nums[i] - nums[i-1] - 1)
		}
	}
	if n - nums[m-1] - 1 + nums[0] >= 1 {
		intervals = append(intervals, n - nums[m-1] - 1 + nums[0])
	}
	sort.Slice(intervals, func(i, j int) bool {
		return intervals[j] < intervals[i]
	})
	cnt := 0
	ans := 0
	for i := range intervals {
		if intervals[i] - cnt * 2 <= 0 {
			fmt.Fprintln(ww, n - ans)
			return
		} else if intervals[i] - cnt * 2 == 1 {
			fmt.Fprintln(ww, n - ans - 1)
			return
		}
		ans += intervals[i] - cnt * 2 - 1
		cnt += 2
	}
	fmt.Fprintln(ww, n - ans)
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		tmp := readArrInt(input)
		arr := readArrInt(input)
		fmt.Println(solve(tmp[0], tmp[1], arr))
	}
}

func solve(n int, m int, arr []int) int {
	sort.Ints(arr)
	gaps := []int{}
	for i := 1; i < m; i++ {
		gaps = append(gaps, arr[i]-arr[i-1]-1)
	}
	gaps = append(gaps, arr[0]-arr[m-1]+n-1)
	sort.Sort(sort.Reverse(sort.IntSlice(gaps)))
	neg_result := 0
	for i := 0; i < m; i++ {
		gaps[i] -= i*4 + 1
	}
	// fmt.Println(gaps)
	for i := 0; i < m; i++ {
		if gaps[i] >= 0 {
			neg_result += gaps[i]
		}
		if gaps[i] == 0 {
			neg_result += 1
		}
	}
	// fmt.Println("Saved: ", neg_result, "Infected: ", n-neg_result)
	return n - neg_result
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return int64(n)
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		infected := readNNums(reader, m)
		res := solve(n, m, infected)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n int, m int, infected []int) int {
	// 每个已感染的house，每天的贡献为1
	// 所以需要protect越多的house，应该是让传播的天数越低越好，而且应该是成对处理
	if m == 0 {
		return 0
	}

	if m == 1 {
		// use two days to protect
		return 2
	}

	var segs []Seg

	sort.Ints(infected)

	for i := 1; i < m; i++ {
		l := infected[i] - infected[i-1] - 1

		if l > 0 {
			segs = append(segs, Seg{infected[i-1] + 1, infected[i] - 1, l})
		}
	}

	segs = append(segs, Seg{infected[m-1] + 1, infected[0] - 1 + n, infected[0] - 1 + n - (infected[m-1] + 1) + 1})

	sort.Slice(segs, func(i, j int) bool {
		return segs[i].seg_len > segs[j].seg_len
	})

	var res int

	for i, day := 0, 0; i < len(segs); i++ {
		cur := segs[i]
		// 两头感染
		l := cur.left
		r := cur.right
		l += day
		r -= day
		if l < r {
			r--
			res += r - l + 1
			day += 2
		} else if l == r {
			res++
			day++
		} else {
			break
		}
	}

	return n - res
}

type Seg struct {
	left    int
	right   int
	seg_len int
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		tmp := readArrInt(input)
		arr := readArrInt(input)
		fmt.Println(solve(tmp[0], tmp[1], arr))
	}
}

func solve(n int, m int, arr []int) int {
	sort.Ints(arr)
	gaps := []int{}
	for i := 1; i < m; i++ {
		gaps = append(gaps, arr[i]-arr[i-1]-1)
	}
	gaps = append(gaps, arr[0]-arr[m-1]+n-1)
	sort.Sort(sort.Reverse(sort.IntSlice(gaps)))
	neg_result := 0
	cheat := 0
	// fmt.Println(gaps)
	for i := 0; i < m; i++ {
		if cheat >= gaps[i] {
			if cheat-gaps[i] == 3 && gaps[i-1] < cheat-2 {
				neg_result++
			}
			break
		}
		neg_result += gaps[i] - 1 - cheat
		cheat += 4
	}
	// fmt.Println("Saved: ", neg_result, "Infected: ", n-neg_result)
	return n - neg_result
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return int64(n)
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		tmp := readArrInt(input)
		arr := readArrInt(input)
		fmt.Println(solve(tmp[0], tmp[1], arr))
	}
}

func solve(n int, m int, arr []int) int {
	sort.Ints(arr)
	gaps := []int{}
	for i := 1; i < m; i++ {
		gaps = append(gaps, arr[i]-arr[i-1]-1)
	}
	gaps = append(gaps, arr[0]-arr[m-1]+n-1)
	sort.Sort(sort.Reverse(sort.IntSlice(gaps)))
	neg_result := 0
	cheat := 0
	// fmt.Println(gaps)
	for i := 0; i < m; i++ {
		if cheat >= gaps[i] {
			if cheat-gaps[i] == 3 && gaps[i-1] < cheat {
				neg_result++
			}
			break
		}
		neg_result += gaps[i] - 1 - cheat
		cheat += 4
	}
	// fmt.Println("Saved: ", neg_result, "Infected: ", n-neg_result)
	return n - neg_result
}

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return int64(n)
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}


package main

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

func readline(r *bufio.Reader) []int {
	l, _ , err := r.ReadLine()
	if err != nil {
		panic(err)
	}
	var res []int
	for _, s := range strings.Split(string(l), " ") {
		n, err := strconv.ParseInt(s, 10, 64)
		if err != nil {
			panic(err)
		}
		res = append(res, int(n))
	}
	return res
}

func main() {
	var t int
	_, err := fmt.Scanf("%d\n", &t)
	if err != nil {
		panic(err)
	}

	r := bufio.NewReader(os.Stdin)
	for i := 0; i < t; i++ {
		nx := readline(r)
		n, x := nx[0], nx[1]

		var degree int
		for j := 0; j < n-1; j++ {
			edge := readline(r)
			if edge[0] == x || edge[1] == x {
				degree++
			}
		}

		if degree <= 1 {
			fmt.Printf("Ayush\n")
		} else {
			if n % 2 == 0 {
				fmt.Printf("Ayush\n")
			} else {
				fmt.Printf("Ashish\n")
			}
		}
	}
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, x := readTwoNums(reader)
		E := make([][]int, n-1)
		for i := 0; i < n-1; i++ {
			E[i] = readNNums(reader, 2)
		}
		fmt.Println(solve(n, x, E))
	}
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const A = "Ayush"
const B = "Ashish"

func solve(n int, x int, E [][]int) string {
	if n == 1 {
		return A
	}
	degree := make([]int, n+1)
	for _, e := range E {
		u, v := e[0], e[1]
		degree[u]++
		degree[v]++
	}

	if degree[x] == 1 {
		return A
	}
	if n&1 == 1 {
		return B
	}
	return A
}

package main

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

var checked []bool
var edges [][]int
var cnt int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, x := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &x)
		x--
		edges = make([][]int, n)
		checked = make([]bool, n)
		for i := 0; i < n-1; i++ {
			o, p := 0, 0
			fmt.Fscanf(in, "%d %d\n", &o, &p)
			o--
			p--
			//fmt.Println(o, p)
			edges[o] = append(edges[o], p)
			edges[p] = append(edges[p], o)
		}
		ds := []int{}
		checked[x] = true
		for _, q := range edges[x] {
			cnt = 0
			dfs(q)
			ds = append(ds, cnt)
		}
		if canWin(ds) {
			fmt.Fprintf(out, "Ayush\n")
		} else {
			fmt.Fprintf(out, "Ashish\n")
		}
	}
	return
}

func canWin(a []int) bool {
	//fmt.Println(a)
	if len(a) <= 1 {
		return true
	}
	sum := 0
	for i := range a {
		sum += a[i]
	}
	if (sum-2)%2 == 0 {
		return false
	}
	return true
}

func dfs(cur int) {
	cnt++
	checked[cur] = true
	for _, next := range edges[cur] {
		if !checked[next] {
			dfs(next)
		}
	}
}

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)

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

	for t := in(); t > 0; t-- {
		n, x := in(), in()
		x--

		g := make([][]int, n)

		for i := range g {
			g[i] = make([]int, 0)
		}

		for i := 0; i < n-1; i++ {
			u, v := in(), in()
			g[u-1] = append(g[u-1], v-1)
			g[v-1] = append(g[v-1], u-1)
		}

		if len(g[x]) <= 1 {
			fmt.Println("Ayush")
		} else {
			z := n - 2

			if z%2 == 0 {
				fmt.Println("Ayush")
			} else {
				fmt.Println("Ashish")
			}
		}
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1363/C
*/

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
	n, x int
	D    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		x--
		D = make([]int, n)
		for j := 0; j < n-1; j++ {
			a, b := ReadInt2()
			a--
			b--

			D[a]++
			D[b]++
		}

		solve()
	}
}

func solve() {
	if D[x] == 1 || n == 1 {
		fmt.Println("Ayush")
		return
	}

	if n%2 == 0 {
		fmt.Println("Ayush")
	} else {
		fmt.Println("Ashish")
	}
}

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

/*********** 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"
)

// github.com/EndlessCheng/codeforces-go
func CF1363C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var t, n, x, v, w int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &x)
		x--
		g := make([][]int, n)
		for i := 1; i < n; i++ {
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}
		if len(g[x]) <= 1 || n&1 == 0 {
			Fprintln(out, "Ayush")
		} else {
			Fprintln(out, "Ashish")
		}
	}
}

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

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int
	fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n, x int
		fmt.Fscan(r, &n, &x)
		x--
		e := make([]int, n)
		for i := 0; i < n-1; i++ {
			var u, v int
			fmt.Fscan(r, &u, &v)
			u--
			v--
			e[u]++
			e[v]++
		}
		if e[x] <= 1 {
			fmt.Fprintln(w, "Ayush")
			continue
		}
		if (n-1)%2 == 1 {
			fmt.Fprintln(w, "Ayush")
		} else {
			fmt.Fprintln(w, "Ashish")
		}
	}
}

package main

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

func readline(r *bufio.Reader) []int {
	l, _ , err := r.ReadLine()
	if err != nil {
		panic(err)
	}
	var res []int
	for _, s := range strings.Split(string(l), " ") {
		n, err := strconv.ParseInt(s, 10, 64)
		if err != nil {
			panic(err)
		}
		res = append(res, int(n))
	}
	return res
}

func main() {
	var t int
	_, err := fmt.Scanf("%d\n", &t)
	if err != nil {
		panic(err)
	}

	r := bufio.NewReader(os.Stdin)
	for i := 0; i < t; i++ {
		nx := readline(r)
		n, x := nx[0], nx[1]

		var degree int
		for j := 0; j < n-1; j++ {
			edge := readline(r)
			if edge[0] == x || edge[1] == x {
				degree++
			}
		}

		if degree == 1 {
			fmt.Printf("Ayush\n")
		} else {
			if n % 2 == 0 {
				fmt.Printf("Ayush\n")
			} else {
				fmt.Printf("Ashish\n")
			}
		}
	}
}

package main

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

var checked []bool
var edges [][]int
var cnt int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, x := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &x)
		x--
		edges = make([][]int, n)
		checked = make([]bool, n)
		for i := 0; i < n-1; i++ {
			o, p := 0, 0
			fmt.Fscanf(in, "%d %d\n", &o, &p)
			o--
			p--
			//fmt.Println(o, p)
			edges[o] = append(edges[o], p)
			edges[p] = append(edges[p], o)
		}
		ds := []int{}
		checked[x] = true
		for _, q := range edges[x] {
			cnt = 0
			dfs(q)
			ds = append(ds, cnt)
		}
		if canWin(ds) {
			fmt.Fprintf(out, "Ayush\n")
		} else {
			fmt.Fprintf(out, "Ashish\n")
		}
	}
	return
}

func canWin(a []int) bool {
	//fmt.Println(a)
	if len(a) <= 1 {
		return true
	}
	sum := 0
	for i := range a {
		sum += a[i]
	}
	if (sum-len(a))%2 == 0 {
		return false
	}
	return true
}

func dfs(cur int) {
	cnt++
	checked[cur] = true
	for _, next := range edges[cur] {
		if !checked[next] {
			dfs(next)
		}
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1363/C
*/

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
	n, x int
	D    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		x--
		D = make([]int, n)
		for j := 0; j < n-1; j++ {
			a, b := ReadInt2()
			a--
			b--

			D[a]++
			D[b]++
		}

		solve()
	}
}

func solve() {
	if D[x] == 1 {
		fmt.Println("Ayush")
		return
	}

	if n%2 == 0 {
		fmt.Println("Ayush")
	} else {
		fmt.Println("Ashish")
	}
}

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

/*********** 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"
)

// github.com/EndlessCheng/codeforces-go
func CF1363C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var t, n, x, v, w int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &x)
		x--
		g := make([][]int, n)
		for i := 1; i < n; i++ {
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}
		if len(g[x]) == 1 || (n-3)&1 == 1 {
			Fprintln(out, "Ayush")
		} else {
			Fprintln(out, "Ashish")
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1363C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var t, n, x, v, w int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &x)
		x--
		g := make([][]int, n)
		for i := 1; i < n; i++ {
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}
		if len(g[x]) == 1 || (n-1-len(g[x]))&1 == 1 {
			Fprintln(out, "Ayush")
		} else {
			Fprintln(out, "Ashish")
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1363C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var t, n, x, v, w int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &x)
		x--
		g := make([][]int, n)
		for i := 1; i < n; i++ {
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}
		if len(g[x]) == 1 || n&1 == 0 {
			Fprintln(out, "Ayush")
		} else {
			Fprintln(out, "Ashish")
		}
	}
}

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

package main

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

var (
	e [][]int
	n int
)

func dfs(u, p int) int {
	var ret int
	for _, v := range e[u] {
		if v == p {
			continue
		}
		ret += dfs(v, u)
	}
	return ret + 1
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int
	fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var x int
		fmt.Fscan(r, &n, &x)
		x--
		e = make([][]int, n)
		for i := 0; i < n-1; i++ {
			var u, v int
			fmt.Fscan(r, &u, &v)
			u--
			v--
			e[u] = append(e[u], v)
			e[v] = append(e[v], u)
		}
		if len(e[x]) == 1 {
			fmt.Fprintln(w, "Ayush")
			continue
		}
		ret := dfs(x, x) - 1
		if ret%2 == 0 {
			fmt.Fprintln(w, "Ashish")
		} else {
			fmt.Fprintln(w, "Ayush")
		}
	}
}

package main

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

var (
	e [][]int
	n int
)

func dfs(u, p int) int {
	var ret int
	for _, v := range e[u] {
		if v == p {
			continue
		}
		ret += dfs(v, u)
	}
	return ret
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int
	fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var x int
		fmt.Fscan(r, &n, &x)
		x--
		e = make([][]int, n)
		for i := 0; i < n-1; i++ {
			var u, v int
			fmt.Fscan(r, &u, &v)
			u--
			v--
			e[u] = append(e[u], v)
			e[v] = append(e[v], u)
		}
		if len(e[x]) == 1 {
			fmt.Fprintln(w, "Ayush")
			continue
		}
		ret := dfs(x, x)
		if ret%2 == 0 {
			fmt.Fprintln(w, "Ashish")
		} else {
			fmt.Fprintln(w, "Ayush")
		}
	}
}


package main

import "fmt"

func main(){
	var n int
	fmt.Scan(&n)
	tmp := n
	var result[] int
	for ;; {
		if tmp < 4{
			break
		}
		result = append(result, tmp)
		result = append(result, tmp - 3)
		tmp -= 4
	}
	if tmp == 0{
		fmt.Println(0)
	}else  if tmp == 1{
		fmt.Println(1)
		result = append(result, 1)
	}else if tmp == 2{
		fmt.Println(1)
		result = append(result, 1)
	}else if tmp == 3{
		fmt.Println(0)
		result = append(result, 3)
	}
	fmt.Print(len(result))
	for _, each := range result{
		fmt.Printf(" %d", each)
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

func main() {
	var n int32
	fmt.Scan(&n)
	if n%2 == 0 {
		fmt.Println(n % 4 / 2)
		fmt.Print(n / 2)
		for i := int32(1); i < n/2; i++ {
			if i%2 == 0 {
				continue
			}
			fmt.Printf(" %d %d", i, n-i+1)
		}
		if n%4 == 2 {
			fmt.Printf(" %d", n/2)
		}
		fmt.Println()
		return
	}
	fmt.Println((n + 1) % 4 / 2)
	fmt.Print(n / 2)
	for i := int32(2); i <= n/2; i++ {
		if i%2 == 1 {
			continue
		}
		fmt.Printf(" %d %d", i, n-i+2)
	}
	if (n-1)%4 != 0 {
		fmt.Printf(" %d", n/2+2)
	}
	fmt.Println()
}

package main

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

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
}

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

type pair struct {
	first int
	second int
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

func main() {
	in := bufio.NewReader(os.Stdin)
	//in, _ := os.Open("a.txt")
	var n int
	fmt.Fscanf(in, "%d", &n)
	sum := (int64(n) * int64(n + 1)) / 2
	fmt.Println(sum % 2)
	if n % 2 == 0 {
		fmt.Print(n / 2," ")
		for i := 1; i < n / 2; i +=2 {
			fmt.Print(i, " ", n - i + 1, " ")
		}
		if sum % 2 == 1 {
			fmt.Println(n / 2)
		}
	} else {
		idx := int64(n) - 1
		var ans []int64
		//ans = append(ans, int64(n))
		var t int64
		for t = int64(n); t <= sum / 2 + sum % 2; t,idx = t + idx, idx - 1 {
			if t <= sum / 2 + sum % 2 {
				ans = append(ans, idx + 1)
			}
		}
		if sum / 2 + sum % 2 - (t - idx - 1) != 0 {
			ans = append(ans, sum / 2 + sum % 2 - (t - idx - 1))
		}
		fmt.Print(len(ans)," ")
		for i := range ans {
			fmt.Print(ans[i]," ")
		}
	}
}