An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?

The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train.  The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.

Print a single integer — the minimum number of actions needed to sort the railway cars.

NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.

package main

import "fmt"

func main(){
	var n int
	var t int
	var length int
	var max_ int
	var length_ int
	fmt.Scanf("%d ",&n)
	seq := make([]int,n)
	for i := 0;i < n;i++{
		fmt.Scanf("%d",&t)
		seq[t - 1] = i
	}
	for i := 0;i < n;i++{
		t = seq[i]
		if(t > max_){
			length_++
			max_ = t
		}else{
			if(length_ > length){
				length = length_
			}
			length_ = 1
			max_ = t
		}
	}
	if(length_ > length){
				length = length_
	}
	fmt.Print(n - length)
}

package main

import "fmt"

func main(){
	var n int
	var t int
	var length int
	var max_ int
	var length_ int
	var seq [100000]int
	fmt.Scanf("%d ",&n)
	for i := 0;i < n;i++{
		fmt.Scanf("%d",&t)
		seq[t - 1] = i
	}
	for i := 0;i < n;i++{
		t = seq[i]
		if(t > max_){
			length_++
			max_ = t
		}else{
			if(length_ > length){
				length = length_
			}
			length_ = 1
			max_ = t
		}
	}
	if(length_ > length){
				length = length_
	}
	fmt.Print(n - length)
}

package main

import (
	"fmt"
	"io"
)

const maxN int = 100002

var pos [maxN]int
var dpf [maxN]int
var dpb [maxN]int

func DP(n int) int {
	var ret int = n - 1
	dpf[0] = 0
	dpb[0] = 0
	dpf[n+1] = 0
	dpb[n+1] = 0
	for i := 1; i <= n; i++ {
		dpf[i] = 1
		if pos[i-1] < pos[i] {
			dpf[i] = dpf[i-1] + 1
		}
	}
	for i := n; i >= 1; i-- {
		dpb[i] = 1
		if pos[i+1] > pos[i] {
			dpb[i] = dpb[i+1] + 1
		}
	}
	for i := 1; i <= n; i++ {
		var sum int = (i - dpf[i]) + (n - i + 1 - dpb[i])
		if sum < ret {
			ret = sum
		}
	}
	return ret
}

func main() {
	var n int
	for {
		var _, err = fmt.Scanf("%d\n", &n)
		if err == io.EOF {
			break
		}
		for i := 1; i <= n; i++ {
			var tmp int
			fmt.Scanf("%d", &tmp)
			pos[tmp] = i
		}
		fmt.Scanf("\n")
		pos[0] = 0
		pos[n+1] = n + 1
		fmt.Printf("%d\n", DP(n))
	}
}

package main

import (
	"fmt"
	//"io"
)

const maxN int = 100002

var pos [maxN]int
var dpf [maxN]int
var dpb [maxN]int

func DP(n int) int {
	var ret int = n - 1
	dpf[0] = 0
	dpb[0] = 0
	dpf[n+1] = 0
	dpb[n+1] = 0
	for i := 1; i <= n; i++ {
		dpf[i] = 1
		if pos[i-1] < pos[i] {
			dpf[i] = dpf[i-1] + 1
		}
	}
	for i := n; i >= 1; i-- {
		dpb[i] = 1
		if pos[i+1] > pos[i] {
			dpb[i] = dpb[i+1] + 1
		}
	}
	for i := 1; i <= n; i++ {
		var sum int = (i - dpf[i]) + (n - i + 1 - dpb[i])
		if sum < ret {
			ret = sum
		}
	}
	return ret
}

func main() {
	var n int
	//for {
	//	var _, err = fmt.Scanf("%d\n", &n)
	//	if err == io.EOF {
	//		break
	//	}
		fmt.Scanf("%d\n", &n)
		for i := 1; i <= n; i++ {
			var tmp int
			fmt.Scanf("%d", &tmp)
			pos[tmp] = i
		}
		fmt.Scanf("\n")
		pos[0] = 0
		pos[n+1] = n + 1
		fmt.Printf("%d\n", DP(n))
	//}
}

package main

import "fmt"

func main(){
	var n int
	var t int
	var length int
	var max_ int
	var length_ int
	fmt.Scanf("%d",&n)
	for i := 0;i < n;i++{
		fmt.Scanf("%d",&t)
		if(t > max_){
			length_++
			max_ = t
		}else{
			if(length_ > length){
				length = length_
			}
			length_ = 1
			max_ = t
		}
	}
	if(length_ > length){
				length = length_
	}
	fmt.Print(n - length)
}

package main

import "fmt"

func main(){
	var n int
	var t int
	var length int
	var max_ int
	var length_ int
	fmt.Scanf("%d ",&n)
	for i := 0;i < n;i++{
		fmt.Scanf("%d ",&t)
		if(t > max_){
			length_++
			max_ = t
		}else{
			if(length_ > length){
				length = length_
			}
			length_ = 1
			max_ = t
		}
	}
	if(length_ > length){
				length = length_
	}
	fmt.Print(n - length)
}

package main

import "fmt"

func main(){
	var n int
	var t int
	var length int
	var max_ int
	var length_ int
	fmt.Scanf("%d ",&n)
	for i := 0;i < n;i++{
		fmt.Scanf("%d",&t)
		if(t > max_){
			length_++
			max_ = t
		}else{
			if(length_ > length){
				length = length_
			}
			length_ = 1
			max_ = t
		}
	}
	if(length_ > length){
				length = length_
	}
	fmt.Print(n - length)
}

package main

import (
	"fmt"
	"io"
)

const maxN int = 100002

var pos [maxN]int
var dpf [maxN]int
var dpb [maxN]int

func DP(n int) int {
	var ret int = n - 1
	dpf[0] = 0
	dpb[0] = 0
	dpf[n+1] = 0
	dpb[n+1] = 0
	for i := 1; i <= n; i++ {
		dpf[i] = 1
		if pos[i-1] < pos[i] {
			dpf[i] = dpf[i-1] + 1
		}
	}
	for i := n; i >= 1; i-- {
		dpb[i] = 1
		if pos[i+1] > pos[i] {
			dpb[i] = dpb[i+1] + 1
		}
	}
	for i := 1; i <= n; i++ {
		var sum int = (i - dpf[i]) + (n - i + 1 - dpb[i])
		if sum < ret {
			ret = sum
		}
	}
	return ret
}

func main() {
	var n int
	for {
		var _, err = fmt.Scanf("%d", &n)
		if err == io.EOF {
			break
		}
		fmt.Printf("n = %d\n", n);
		for i := 1; i <= n; i++ {
			var tmp int
			fmt.Scanf("%d", &tmp)
			fmt.Printf("%d ", tmp)
			pos[tmp] = i
		}
		fmt.Printf("\n")
		pos[0] = 0
		pos[n+1] = n + 1
		fmt.Printf("%d\n", DP(n))
	}
}

package main

import (
	"fmt"
	"io"
)

const maxN int = 100002

var pos [maxN]int
var dpf [maxN]int
var dpb [maxN]int

func DP(n int) int {
	var ret int = n
	dpf[n+1] = 0
	dpb[n+1] = 0
	for i := 1; i <= n; i++ {
		dpf[i] = 1
		if pos[i-1] < pos[i] {
			dpf[i] = dpf[i-1] + 1
		}
	}
	for i := n; i >= 1; i-- {
		dpb[i] = 1
		if pos[i+1] > pos[i] {
			dpb[i] = dpb[i+1] + 1
		}
	}
	for i := 1; i <= n; i++ {
		var sum int = (i - dpf[i]) + (n - i + 1 - dpb[i])
		if sum < ret {
			ret = sum
		}
	}
	return ret
}

func main() {
	var n int
	for {
		var _, err = fmt.Scanf("%d", &n)
		if err == io.EOF {
			break
		}
		var tmp int
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &tmp)
			pos[tmp] = i
		}
		pos[0] = 0
		pos[n+1] = n + 1
		fmt.Printf("%d\n", DP(n))
	}
}

package main

import (
	"fmt"
	"io"
)

const maxN int = 100002

var pos [maxN]int
var dpf [maxN]int
var dpb [maxN]int

func DP(n int) int {
	var ret int = n - 1
	dpf[0] = 0
	dpb[0] = 0
	dpf[n+1] = 0
	dpb[n+1] = 0
	for i := 1; i <= n; i++ {
		dpf[i] = 1
		if pos[i-1] < pos[i] {
			dpf[i] = dpf[i-1] + 1
		}
	}
	for i := n; i >= 1; i-- {
		dpb[i] = 1
		if pos[i+1] > pos[i] {
			dpb[i] = dpb[i+1] + 1
		}
	}
	for i := 1; i <= n; i++ {
		var sum int = (i - dpf[i]) + (n - i + 1 - dpb[i])
		if sum < ret {
			ret = sum
		}
	}
	return ret
}

func main() {
	var n int
	for {
		var _, err = fmt.Scanf("%d", &n)
		if err == io.EOF {
			break
		}
		for i := 1; i <= n; i++ {
			var tmp int
			fmt.Scanf("%d", &tmp)
			pos[tmp] = i
		}
		pos[0] = 0
		pos[n+1] = n + 1
		fmt.Printf("%d\n", DP(n))
	}
}

package main

import (
	"fmt"
)

const maxN int = 100002

var pos [maxN]int
var dpf [maxN]int
var dpb [maxN]int

func DP(n int) int {
	var ret int = n - 1
	dpf[0] = 0
	dpb[0] = 0
	dpf[n+1] = 0
	dpb[n+1] = 0
	for i := 1; i <= n; i++ {
		dpf[i] = 1
		if pos[i-1] < pos[i] {
			dpf[i] = dpf[i-1] + 1
		}
	}
	for i := n; i >= 1; i-- {
		dpb[i] = 1
		if pos[i+1] > pos[i] {
			dpb[i] = dpb[i+1] + 1
		}
	}
	for i := 1; i <= n; i++ {
		var sum int = (i - dpf[i]) + (n - i + 1 - dpb[i])
		if sum < ret {
			ret = sum
		}
	}
	return ret
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	for i := 1; i <= n; i++ {
		var tmp int
		fmt.Scanf("%d", &tmp)
		pos[tmp] = i
	}
	pos[0] = 0
	pos[n+1] = n + 1
	fmt.Printf("%d\n", DP(n))
}


Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from $$$1$$$, starting from the topmost one. The columns are numbered from $$$1$$$, starting from the leftmost one.Initially, the table hasn't been filled and Polycarp wants to fix it. He writes integers from $$$1$$$ and so on to the table as follows.  The figure shows the placement of the numbers from $$$1$$$ to $$$10$$$. The following actions are denoted by the arrows. The leftmost topmost cell of the table is filled with the number $$$1$$$. Then he writes in the table all positive integers beginning from $$$2$$$ sequentially using the following algorithm.First, Polycarp selects the leftmost non-filled cell in the first row and fills it. Then, while the left neighbor of the last filled cell is filled, he goes down and fills the next cell. So he goes down until the last filled cell has a non-filled neighbor to the left (look at the vertical arrow going down in the figure above).After that, he fills the cells from the right to the left until he stops at the first column (look at the horizontal row in the figure above). Then Polycarp selects the leftmost non-filled cell in the first row, goes down, and so on.A friend of Polycarp has a favorite number $$$k$$$. He wants to know which cell will contain the number. Help him to find the indices of the row and the column, such that the intersection of the row and the column is the cell containing the number $$$k$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing one integer $$$k$$$ ($$$1 \le k \le 10^9$$$) which location must be found.

For each test case, output in a separate line two integers $$$r$$$ and $$$c$$$ ($$$r, c \ge 1$$$) separated by spaces — the indices of the row and the column containing the cell filled by the number $$$k$$$, respectively.

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int64
		fmt.Fscan(in, &n)
		tmp := int64(m.Ceil(m.Sqrt(float64(n)))) - 1
		x, y := min(n - tmp * tmp, tmp + 1), min((tmp + 1) * (tmp + 1) - n + 1, tmp + 1)
		fmt.Fprintln(out, x, y)
	}
}

package main
//this code is written by likely
//do not distribute it freely24325234

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

func main(){
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t,n,i,zc,a,b int64
	fmt.Fscan(in,&t)
	for i=1;i<=t;i++{
		fmt.Fscan(in,&n)
		zc=int64(math.Sqrt(float64(n)))
		if zc*zc==n{
			fmt.Fprintf(out, "%d %d\n", zc, 1)
			continue
		}else{
			zc++
		}
		a=zc*zc
		b=(zc-1)*(zc-1)+1
		if a-n<=n-b {
			fmt.Fprintf(out, "%d %d\n", zc, a-n+1)
		}else{
			fmt.Fprintf(out, "%d %d\n",n-b+1,zc)
		}
	}//233
}

package main
//this code is written by likely
//do not distribute it freely

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

func main(){
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t,n,i,zc,a,b int64
	fmt.Fscan(in,&t)
	for i=1;i<=t;i++{
		fmt.Fscan(in,&n)
		zc=int64(math.Sqrt(float64(n)))
		if zc*zc==n{
			fmt.Fprintf(out, "%d %d\n", zc, 1)
			continue
		}else{
			zc++
		}
		a=zc*zc
		b=(zc-1)*(zc-1)+1
		if a-n<=n-b {
			fmt.Fprintf(out, "%d %d\n", zc, a-n+1)
		}else{
			fmt.Fprintf(out, "%d %d\n",n-b+1,zc)
		}
	}
}//234

package main

import (
	"fmt"
	"math"
)

func print(a int, b int) {
	fmt.Printf("%d %d\n", a, b)
}

func main() {
	var n int
	fmt.Scan(&n)

	for j := 0; j < n; j++ {
		var t int
		fmt.Scan(&t)

		res := int(math.Sqrt(float64(t)))

		res1 := t - res * res

		if res1 == 0 {
			print(res, 1)
		} else if res1 <= res + 1  {
			print(res1, res + 1)
		} else if res1 > res + 1 {
			print(res + 1, res * 2 + 2 - res1)
		}

	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	i:= 1
	count := 0

	a := make([]int, 1000)
	for count < 1000 {
		if i % 3 != 0 && i % 10 != 3 {
			a[count] = i
			count++
		}
		i++
	}

	var n int
	fmt.Scan(&n)

	for j := 0; j < n; j++ {
		var t int
		fmt.Scan(&t)

		res := int(math.Sqrt(float64(t)))

		res1 := t - res * res

		if res1 == 0 {
			fmt.Println(res, " 1")
		} else if res1 <= res + 1  {
			fmt.Println(res1, " ", res + 1)
		} else if res1 > res + 1 {
			fmt.Println(res + 1, " ", res * 2 + 2 - res1)
		}

	}
}

package main

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

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 k int
		fmt.Fscan(in, &k)

		r := 1
		d := 1
		sum := 1
		for sum < k {
			d += 2
			sum += d
			r++
		}

		c := 1
		for sum > k {
			if c < r {
				c++
			} else {
				r--
			}
			sum--
		}

		fmt.Fprintf(out, "%d %d\n", r, c)
	}
}

package main

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

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		var k int64
		fmt.Fscan(r, &k)
		sqrtK := math.Sqrt(float64(k))
		floorSqrtK := math.Floor(sqrtK)
		if floorSqrtK == sqrtK {
			fmt.Printf("%d %d\n", int64(sqrtK), 1)
			continue
		}
		ceilSqrtK := math.Ceil(sqrtK)
		diff := k - int64(floorSqrtK*floorSqrtK)
		if diff <= int64(ceilSqrtK) {
			fmt.Printf("%d %d\n", diff, int64(ceilSqrtK))
		} else {
			fmt.Printf("%d %d\n", int64(ceilSqrtK), int64(floorSqrtK)-diff+int64(ceilSqrtK)+1)
		}
	}
}

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k int64
		Fscan(in, &k)

		left, right := int64(1), k
		for left < right {
			mid := left + ((right - left) >> 1)
			if mid * mid >= k {
				right = mid

			} else {
				left = mid+1
			}
		}
		col, row := left, int64(0)
		start := (col - 1) * (col - 1)
		if k - start <= col {
			row = k - start

		} else {
			row, col = col, col - k + start + col
		}
		Fprintln(out, row, col)
	}
}

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

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k int64
		Fscan(in, &k)

		left, right := int64(1), k
		for left < right {
			mid := left + ((right - left) >> 1)
			if mid * mid >= k {
				right = mid
			} else {
				left = mid + 1
			}
		}
		col, row := left, int64(0)
		start := (col-1) * (col-1) + 1
		if k - start <= col - 1 {
			row = 1 + k - start

		} else {
			row, col = col, col - k + (start + col - 1)
		}
		Fprintln(out, row, col)
	}
}

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

func abs(num int) int {
	if num >= 0 {
		return num
	}
	return -num
}

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

                            Online Go Lang Compiler.
                Code, Compile, Run and Debug Go Lang program online.
Write your code in this editor and press "Run" button to execute it.

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

package main

import "fmt"
import "bufio"
import "os"
//import "sort"

func main() {
    in := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(in, &n)
    for ; n > 0; n--{
        var k int
        fmt.Fscan(in, &k)
        var i int
        for ; i * i < k; i++ {

        }
        i--
        c := k - i * i
        if (c > i) {
            fmt.Println(i + 1," ", i + 2 - (c - i))
        } else {
            fmt.Println(c," ", i + 1)
        }
    }

}

package main

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

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

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
  var t int
  scanner.Scan()
  t = toInt(scanner.Bytes())
  for g := 0; g < t; g++{
    var n int
    scanner.Scan()
    n = toInt(scanner.Bytes())
    var m int = int(math.Floor(math.Sqrt(float64(n - 1))))
    n -= m * m
    if n > m{
      fmt.Println(m + 1, m + 2 - (n - m))
    }else{
      fmt.Println(n, m + 1)
    }
  }
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x int
		fmt.Fscan(in,&x)
		if isIntegral(math.Sqrt(float64(x))) == true {
			fmt.Fprintln(out,int(math.Sqrt(float64(x))),1)
		} else {
			l:= int(math.Sqrt(float64(x))) // 2
			y_cord:= l*l+1 // 5
			if x < l+y_cord {
				fmt.Fprintln(out,(l+1)-(l+y_cord-x),l+1)
			} else {
				fmt.Fprintln(out,l+1,(l+1)*(l+1)-x+1)
			}
		}
	}
}
func isIntegral(val float64) bool {
	return val == float64(int(val))
}

package main

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

func LowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, o, tot := 0, []int{}, 0
	for i := 1; tot <= int(1e9); i += 2 {
		tot += i
		o = append(o, tot)
	}
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		n := 0
		fmt.Fscan(f, &n)
		p := LowerBound(o, n)
		if n == 1 {
			fmt.Fprintln(w, 1, 1)
		} else if n <= o[p-1]+p+1 {
			fmt.Fprintln(w, n-o[p-1], p+1)
		} else {
			fmt.Fprintln(w, p+1, o[p]-n+1)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1560C
Date: 21/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1560/C
Problem: CF1560C
**/
func (in *CF1560C) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt64()
		aux := int64(1)
		init := int64(1)
		x := int64(0)
		for ; init < n; init += aux {
			x++
			aux += 2
		}

		start := init - (aux - 2) - 1

		diff := n - start

		if diff <= int64(math.Ceil(float64(aux/2))) {
			fmt.Println(diff+1, x+1)
		} else {
			diff -= int64(math.Ceil(float64(aux / 2)))
			fmt.Println(x+1, x-diff+1)
		}

	}
}

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

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

package main

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

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

func solve(k int) string {
	var i int
	for i*i < k {
		i++
	}
	j := (i - 1) * (i - 1)
	if k <= j+i {
		return fmt.Sprintf("%d %d", k-j, i)
	} else {
		return fmt.Sprintf("%d %d", i, i*i-k+1)
	}
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &k)
		fmt.Println(solve(k))
	}
}

package main

import (
	"fmt"
	"math"
)

const MAX = 1000000000

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

	row, col := 1, 1

	n := int(math.Ceil(math.Sqrt(float64(k))))
	start, end := (n-1)*(n-1)+1, n*n

	if end-n+1 < k {
		row, col = n, end-k+1
	} else {
		row, col = k-start+1, n
	}

	fmt.Println(row, col)
}

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

	for ; test > 0; test-- {
		c()
	}
}

package main

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

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

	var T, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &k)
		base, c := 0, 1
		for ; k > c; c += 2 {
			k -= c
			base += c
		}
		r := (c + 1) / 2
		if k < r {
			Fprintln(out, k, r)
		} else {
			Fprintln(out, r, c-k+1)
		}
	}
}

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

package main

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

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

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}

func solve() {
	var k int64
	fmt.Fscan(in, &k)
	var row int64 = 1
	var col int64 = 1

	for (row * col) < k {
		row++
		col++
	}
	var currentNumber = row * col
	var currentCol = 1
	var currentRow = row
	for currentNumber != k && currentCol < int(col) {
		currentNumber--
		currentCol++
	}
	for currentRow >= 1 && currentNumber != k {
		currentRow--
		currentNumber--
	}
	fmt.Println(currentRow, " ", currentCol)
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

func (r runeSort) Len() int           { return len(r) }
func (r runeSort) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r runeSort) Less(i, j int) bool { return r[i] < r[j] }

package main

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

func Abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

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

	var t int16
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var k int64
		fmt.Fscan(in, &k)
		var x int64 = 1
		var a int64 = -1
		var i int64 = 0

		for k >= x {
			a += 2
			x += a
			i += 1
		}

		m := k - (x - a) + 1
		if m <= i {
			fmt.Fprintln(out, m, i)
		} else {
			fmt.Fprintln(out, i, 2*i-m)
		}
	}
}

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

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var k int
		fmt.Scan(&k)
		j := 1
		for j*j < k {
			j++
		}
		j--
		k -= j * j
		if k <= j {
			fmt.Println(k, j+1)
			continue
		}
		k -= j
		fmt.Println(j+1, j-k+2)
	}
}

package main

import (
	"fmt"
	"math"
	// "log"
)

func solve(val int) (int,int){

	sqrt := math.Sqrt(float64(val))
	x := int(math.Ceil(sqrt))

	start := (x-1)*(x-1) + 1
	mid := (start + x) - 1

	if val >= mid {
		y := x - (val - mid)
		return x,y
	} else {
		y := (val - start) + 1
		return y, x
	}

	return 0,0
}

func main() {
	// trying to generate a filled table of 100 to spot a relation.
	// -> not applicable by computation or manually (brain)

	// I found it!
	var testcases int
	fmt.Scanf("%d\n", &testcases)

	for ; testcases > 0; testcases-- {
		var val int
		fmt.Scanf("%d\n", &val)
		fmt.Println(solve(val))
	}
}

package main

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

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

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

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

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

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

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

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

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

var t int

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

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

		// ARR := make([]int, n)
		// for i := 0; i < n; i++ {
		// 	fmt.Fscan(input, &ARR[i])

		// }

		// q := int(math.Sqrt(float64(k)))

		// if q*q == k {

		// }
		begin := k
		aamount := 1
		layer := 0
		for {
			if begin-aamount < 0 {
				break
			} else {
				begin = begin - aamount
				aamount = aamount + 2
				layer++
			}
		}
		var ansrow, anscolumn int

		if begin == 0 {
			anscolumn = 1
			ansrow = layer
		} else {
			if begin == layer+1 {
				anscolumn = 1 + layer
				ansrow = layer + 1
			} else {
				if begin <= layer {
					anscolumn = layer + 1
					ansrow = begin
				} else {
					ansrow = layer + 1
					artan := begin - layer - 1
					anscolumn = layer + 1 - artan
				}
			}
		}

		fmt.Println(ansrow)
		fmt.Println(anscolumn)

	}

}

package main

import (
	"fmt"
	"math"
)

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

func dd(a int) {
	q := int(math.Sqrt(float64(a)))
	if q*q == a {
		fmt.Println(q, "1")
		return
	}
	a = a - q*q
	if a <= q+1 {
		fmt.Println(a, q+1)
	} else {
		fmt.Println(q+1, 2*(q+1)-a)
	}
	return
}

package main

import "fmt"

func main() {
    var tC int
    fmt.Scanln(&tC)

    for i := 0; i < tC; i++ {
        var k int
        fmt.Scanln(&k)

        middle, pos := findMiddle(k)
        if k < middle {
            b := pos
            a := pos - (middle - k)
            fmt.Printf("%d %d\n", a, b)
        } else if k > middle {
            a := pos
            b := pos - (k - middle)
            fmt.Printf("%d %d\n", a, b)
        } else {
            fmt.Printf("%d %d\n", pos, pos)
        }

    }
}

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

func findMiddle(k int) (int, int) {
    middle := 1
    prev_middle := middle
    step := 2
    pos := 1
    for middle < k {
        prev_middle = middle
        middle += step
        step += 2
        pos++
    }
    diff := abs(middle - k)
    prev_diff := abs(prev_middle - k)
    if diff > prev_diff {
        middle = prev_middle
        pos -= 1
    }
    return middle, pos
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var number int
		fmt.Scan(&number)
		if isPerfectSquare(number) {
			fmt.Printf("%v %v\n", int(math.Sqrt(float64(number))), 1)
		} else {
			square := int(math.Floor(math.Sqrt(float64(number))))
			diff := number - square*square
			if diff <= square+1 {
				fmt.Printf("%v %v\n", diff, square+1)
			} else {
				fmt.Printf("%v %v\n", square+1, square+(square+1-diff)+1)
			}
		}
	}
}

func isPerfectSquare(no int) bool {
	int_root := int(math.Sqrt(float64(no)))
	return int_root*int_root == no
}

package main

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

/* --- Solution C --- */
func solve(in *In, out *Out) {
	k := in.nextDouble()

	sqrt := math.Ceil(math.Sqrt(k))
	sq := math.Pow(sqrt, 2)
	if k > sq-sqrt {
		out.println(int(sqrt), int(sq)-int(k)+1)
	} else {
		out.println(int(sqrt)-(int(sq-sqrt)-int(k)+1), int(sqrt))
	}
}

func run(in *In, out *Out) {
	cases(in, out)
	// solve(in, out)
}

func main() {
	in := NewIn()
	out := NewOut()
	defer out.flush()

	run(in, out)
}

func cases(in *In, out *Out) {
	tt := in.nextInt()
	for ; tt > 0; tt-- {
		solve(in, out)
	}
}

/* --- I/O --- */
const BUF_MAX_CAP int = 1024

type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	scn := bufio.NewScanner(os.Stdin)

	buf := make([]byte, BUF_MAX_CAP)
	scn.Buffer(buf, BUF_MAX_CAP)
	scn.Split(bufio.ScanWords)

	return &In{scn}
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

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

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

func (in *In) nextByte() byte {
	in.scanner.Scan()
	return in.scanner.Text()[0]
}

func (in *In) nextDouble() float64 {
	in.scanner.Scan()
	i, _ := strconv.ParseFloat(in.scanner.Text(), 64)
	return i
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

func (out *Out) println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

func (out *Out) printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

func (out *Out) print(a ...interface{}) {
	fmt.Fprint(out.writer, a...)
}

func (out *Out) flush() {
	out.writer.Flush()
}

package main

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

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
	var n int32
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &n)
		w1, w2 := do(n)
		fmt.Fprint(w, w1, w2)
		fmt.Fprintln(w)
	}
}

func do(n int32) (int32, int32) {
	r := int32(0)
	for {
		if r*r < n && n <= (r+1)*(r+1) {
			r += 1
			break
		}
		r++
	}
	a := (r-1)*(r-1) + 1
	b := r * r
	c := (a + b) / 2
	if n < c {
		return (n - a) + 1, r
	}
	return r, (b - n) + 1
}

package main

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

func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var k int
		fmt.Fscan(in,&k)
		now := 1
		cur :=1
		r:=1
		c:=1
		for k>now{
			now += cur+2
			cur = cur+2
			r++
		}
		nums := now-k
		flag:=false
		for i:=1;i<=nums;i++{
			if flag==false {
				c++
				if c == r{
					flag=true
				}
			}else if flag {
				r--
			}
		}
		fmt.Fprintln(out,r,c)
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

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

		solve(k)
	}
}

func solve(k int) {
	var t int
	for i := 1; i < 1e6; i++ {
		if i * i == k {
			fmt.Print(i)
			fmt.Print(" ")
			fmt.Print(1)
			fmt.Println()
			return
		}

		if i * i > k {
			t = i
			break
		}
	}
	prev := (t - 1) * (t - 1) + 1

	if k == t * t - t + 1{
		fmt.Print(t)
		fmt.Print(" ")
		fmt.Print(t)
		fmt.Println()
		return
	}

	if k > t * t - t + 1 {
		fmt.Print(t)
		fmt.Print(" ")
		fmt.Print(t * t - k + 1)
		fmt.Println()
		return

	} else {
		fmt.Print(k - prev + 1)
		fmt.Print(" ")
		fmt.Print(t)
		fmt.Println()
		return
	}

}

package main

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

func main() {
	defer wr.Flush()
	t := scanInt()
	for i := 0; i < t; i++ {
		x, y := solve()
		fmt.Fprintln(wr, x, y)
	}
}

func solve() (int, int) {
	k := scanInt()
	q := int(math.Ceil(math.Sqrt(float64(k))))
	d := k - (q-1)*(q-1)
	if d <= q {
		return d, q
	}
	return q, 2*q - d
}

var (
	sc *bufio.Scanner
	wr *bufio.Writer
)

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr = bufio.NewWriter(os.Stdout)
}

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

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T, k int

	fmt.Fscanf(r, "%d\n", &T)
	for t := 0; t < T; t++ {
		fmt.Fscanf(r, "%d\n", &k)

		c := 1
		for x := 1; ; x++ {
			if c >= k {
				if k <= x {
					fmt.Println(k, x)
				} else {
					fmt.Println(x, x-(k-x))
				}

				break
			}
			k -= c
			c += 2
		}
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int64
		fmt.Fscan(in, &n)
		tmp := int64(m.Ceil(m.Sqrt(float64(n)))) - 1
		x, y := min(n - tmp * tmp, tmp + 1), min((tmp + 1) * (tmp + 1) - n, tmp + 1)
		fmt.Fprintln(out, x, y)
	}
}

package main

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

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int64
		fmt.Fscan(in, &n)
		tmp := int64(m.Ceil(m.Sqrt(float64(n)))) - 1
		x, y := min(n - tmp * tmp, tmp + 1), max((tmp + 1) * (tmp + 1) - n, tmp + 1)
		fmt.Fprintln(out, x, " ", y)
	}
}

package main

import (
	"fmt"
	"math"
)

func print(a int, b int) {
	fmt.Printf("%d %d\n", a, b)
}

func main() {
	var n int
	fmt.Scan(&n)

	for j := 0; j < n; j++ {
		var t int
		fmt.Scan(&t)

		res := int(math.Sqrt(float64(t)))

		res1 := t - res * res

		if res1 <= res + 1  {
			print(res1, res + 1)
		} else if res1 > res + 1 {
			print(res + 1, res * 2 + 2 - res1)
		}

	}
}

package main

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

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		var k int64
		fmt.Fscan(r, &k)
		sqrtK := math.Sqrt(float64(k))
		floorSqrtK := math.Floor(sqrtK)
		if floorSqrtK == sqrtK {
			fmt.Printf("%d %d\n", int64(sqrtK), int64(sqrtK))
			continue
		}
		ceilSqrtK := math.Ceil(sqrtK)
		diff := k - int64(floorSqrtK*floorSqrtK)
		if diff <= int64(ceilSqrtK) {
			fmt.Printf("%d %d\n", diff, int64(ceilSqrtK))
		} else {
			fmt.Printf("%d %d\n", int64(ceilSqrtK), int64(floorSqrtK)-diff+int64(ceilSqrtK)+1)
		}
	}
}

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

                            Online Go Lang Compiler.
                Code, Compile, Run and Debug Go Lang program online.
Write your code in this editor and press "Run" button to execute it.

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

package main

import "fmt"
import "bufio"
import "os"
//import "sort"

func main() {
    in := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(in, &n)
    for ; n > 0; n--{
        var a, b, c int
        fmt.Fscan(in, &a, &b, &c)
        if (b > a) {
            a,b = b,a
        }
        var sz = (a - b) * 2

        if (c > sz || a > sz || b > sz) {
            fmt.Println(-1)
        } else {
            sz /= 2
            if (c > sz) {
                fmt.Println(c - sz)
            } else {
                fmt.Println(c + sz)
            }
        }
    }

}

package main

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

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

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
  var t int
  scanner.Scan()
  t = toInt(scanner.Bytes())
  for g := 0; g < t; g++{
    var n int
    scanner.Scan()
    n = toInt(scanner.Bytes())
    var m int = int(math.Floor(math.Sqrt(float64(n))))
    n -= m * m
    if n > m{
      fmt.Println(m + 1, m + 2 - (n - m))
    }else{
      fmt.Println(n, m + 1)
    }
  }
}


AquaMoon has two binary sequences $$$a$$$ and $$$b$$$, which contain only $$$0$$$ and $$$1$$$. AquaMoon can perform the following two operations any number of times ($$$a_1$$$ is the first element of $$$a$$$, $$$a_2$$$ is the second element of $$$a$$$, and so on): Operation 1: if $$$a$$$ contains at least two elements, change $$$a_2$$$ to $$$\operatorname{min}(a_1,a_2)$$$, and remove the first element of $$$a$$$. Operation 2: if $$$a$$$ contains at least two elements, change $$$a_2$$$ to $$$\operatorname{max}(a_1,a_2)$$$, and remove the first element of $$$a$$$.Note that after a removal of the first element of $$$a$$$, the former $$$a_2$$$ becomes the first element of $$$a$$$, the former $$$a_3$$$ becomes the second element of $$$a$$$ and so on, and the length of $$$a$$$ reduces by one.Determine if AquaMoon can make $$$a$$$ equal to $$$b$$$ by using these operations.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 2\,000$$$) — the number of test cases. Description of test cases follows. The first line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n,m \leq 50$$$, $$$m \leq n$$$) — the lengths of $$$a$$$ and $$$b$$$ respectively. The second line of each test case contains a string $$$a$$$ of length $$$n$$$, consisting only $$$0$$$ and $$$1$$$. The third line of each test case contains a string $$$b$$$ of length $$$m$$$, consisting only $$$0$$$ and $$$1$$$.

For each test case, output "YES" if AquaMoon can change $$$a$$$ to $$$b$$$ by using these options; otherwise, output "NO". You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

NoteIn the first test case, you can use Operation 2 four times to make $$$a$$$ equals to $$$b$$$.In the second test case, you can use Operation 1 four times to make $$$a$$$ equals to $$$b$$$.In the third test case, it can be proved that no matter how we use the operations, it is impossible to make $$$a$$$ equal to $$$b$$$.In the fourth test case, it can be proved that no matter how we use the operations, it is impossible to make $$$a$$$ equal to $$$b$$$.In the fifth test case, you can use Operation 2 three times to make $$$a$$$ become $$$10101$$$, so the first element of $$$a$$$ equals to the first element of $$$b$$$, but it can be proved that no matter how to operate, the second to the fifth elements of $$$a$$$ can't be the same as $$$b$$$.

package main

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

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

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

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

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

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

/**
Run solve the problem CF1704A
Date: 10/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1704/A
Problem: CF1704A
**/
func (in *CF1704A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextInt()
		a := in.NextString()
		b := in.NextString()

		ans := true
		if m > n {
			ans = false
		} else {
			eq := 0
			for i, j := n-1, m-1; j >= 0 && i >= 0; {
				if a[i] == b[j] {
					eq++
					j--
					i--
				} else if eq == m-1 {
					i--
				} else {
					break
				}
			}
			if eq < m {
				ans = false
			}
		}

		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

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

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

package main

import (
    "fmt"
    "strings"
)

func work(a, b string) bool {
    if len(b) > len(a) {
        return false
    }
    if a[len(a)-len(b):] == b {
        return true
    }
    if a[len(a)-len(b)+1:] != b[1:] {
        return false
    }
    return strings.Contains(a[0:len(a)-len(b)+1], b[0:1])
}

func main() {
        var t int
        fmt.Scanf("%d\n", &t)
        for ;t>0; t-- {
            var n, m int
            var a, b string
            fmt.Scanf("%d %d\n", &n, &m)
            fmt.Scanf("%s\n", &a)
            fmt.Scanf("%s\n", &b)

            if work(a, b) {
                    fmt.Println("yes")
            } else {
                    fmt.Println("no")
            }
        }
}

package main

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

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

func CF1704A(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 m, n int
		fmt.Fscan(r, &n, &m)
		var a, b []byte
		fmt.Fscan(r, &a, &b)

		if m == n {
			if bytes.Compare(a, b) == 0 {
				fmt.Fprintln(w, "YES")
			} else {
				fmt.Fprintln(w, "NO")
			}
			continue
		}

		if bytes.Compare(a[n-m+1:], b[1:]) == 0 && bytes.Count(a[:n-m+1], b[:1]) >= 1 {
			fmt.Fprintln(w, "YES")
			continue
		}
		fmt.Fprintln(w, "NO")
	}
}
func max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

package main

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

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
		var a, b string
		fmt.Fscan(in, &n, &m, &a, &b)

		e, o := -1, -1
		for i := 0; i < n-m+1; i++ {
			if a[i] == '0' {
				e = i
			} else {
				o = i
			}
		}
		if (e >= 0 && o >= 0 && a[n-m+1:] == b[1:]) || a[n-m:] == b {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	_, _ = fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var q, w int
		_, _ = fmt.Scanf("%d %d\n", &q, &w)
		var a, b string
		_, _ = fmt.Scanf("%s\n%s\n", &a, &b)
		if len(a) < len(b) {
			fmt.Println("NO")
		} else if a == b {
			fmt.Println("YES")
		} else {
			if strings.HasSuffix(a, b[1:]) {
				if b[0] == '0' {
					if strings.Contains(a[:len(a)-(len(b)-1)], "0") {
						fmt.Println("YES")
					} else {
						fmt.Println("NO")
					}
				} else {
					if strings.Contains(a[:len(a)-(len(b)-1)], "1") {
						fmt.Println("YES")
					} else {
						fmt.Println("NO")
					}
				}
			} else {
				fmt.Println("NO")
			}
		}
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		readString(reader)
		a := readString(reader)
		b := readString(reader)
		res := solve(a, b)
		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	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(a, b string) bool {
	m := len(a)
	n := len(b)
	if m < n {
		return false
	}

	// m >= n

	for n > 1 && a[m-1] == b[n-1] {
		m--
		n--
	}

	if n != 1 {
		return false
	}

	for i := 0; i < m; i++ {
		if a[i] == b[0] {
			return true
		}
	}
	return false
}

package main

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

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)
		var a, b string
		fmt.Fscan(r, &a, &b)
		w1 := do(n, m, a, b)
		fmt.Fprintln(w, w1)
	}
}

func do(n, m int, a, b string) string {
	if !strings.Contains(a[:n-m+1], b[:1]) {
		return "NO"
	}
	if a[n-m+1:] != b[1:] {
		return "NO"
	}
	return "YES"
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)
		var as string
		var bs string
		fmt.Scanf("%s\n", &as)
		fmt.Scanf("%s\n", &bs)
		var diff bool
		for j := 1; j < len(bs); j++ {
			if bs[j] != as[len(as)-len(bs)+j] {
				diff = true
				break
			}
		}
		if !diff {
			var has bool
			for i := 0; i <= len(as)-len(bs); i++ {
				if as[i] == bs[0] {
					has = true
					break
				}
			}
			if !has {
				diff = true
			}
		}
		if diff {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
	}
}

/*
AquaMoon has two binary sequences a and b, which contain only 0 and 1. AquaMoon can perform the following two operations any number of times (a1 is the first element of a, a2 is the second element of a

, and so on):

    Operation 1: if a

contains at least two elements, change a2 to min(a1,a2), and remove the first element of a
.
Operation 2: if a
contains at least two elements, change a2 to max(a1,a2), and remove the first element of a

    .

Note that after a removal of the first element of a
, the former a2 becomes the first element of a, the former a3 becomes the second element of a and so on, and the length of a

reduces by one.

Determine if AquaMoon can make a
equal to b

by using these operations.
Input

The first line contains a single integer t
(1≤t≤2000

) — the number of test cases. Description of test cases follows.

The first line of each test case contains two integers n
, m (1≤n,m≤50, m≤n) — the lengths of a and b

respectively.

The second line of each test case contains a string a
of length n, consisting only 0 and 1

.

The third line of each test case contains a string b
of length m, consisting only 0 and 1

.
Output

For each test case, output "YES" if AquaMoon can change a
to b

by using these options; otherwise, output "NO".

You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).
*/

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Scan(&n, &m)
		var a string
		var b string

		fmt.Scan(&a)
		fmt.Scan(&b)

		for j := 0; j < len(a); j++ {
			if j >= len(b) || a[j] != b[j] {
				if a[0] != b[0] {
					a = a[1:] // remove first element
					j = 0
				} else {
					a = a[0:1] + a[2:] // remove second element
					j = 0
				}
			}
		}
		if a == b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		_ = readArrInt(input)
		s1, _ := input.ReadString('\n')
		s2, _ := input.ReadString('\n')
		s1 = strings.TrimSpace(s1)
		s2 = strings.TrimSpace(s2)
		fmt.Println(solve([]rune(s1), []rune(s2)))
	}
}

func solve(s1 []rune, s2 []rune) string {
	// fmt.Println(s1, " ", s2)
	l1 := len(s1)
	l2 := len(s2)
	for i := 1; i < l2; i++ {
		if s2[i] != s1[l1-l2+i] {
			return "NO"
		}
	}
	for i := 0; i <= l1-l2; i++ {
		if s1[i] == s2[0] {
			return "YES"
		}
	}
	return "NO"
}

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

const cf = true

func solve() {
	var n, m int
	fmt.Fscan(in, &n, &m)
	var a, b string
	fmt.Fscan(in, &a, &b)
	cur := n - 1
	for i := m - 1; i >= 0; i-- {
		if b[i] != a[cur] {
			if i != 0 {
				fmt.Fprintln(out, "NO")
				return
			}
			has := false
			for j := cur; j >= 0; j-- {
				if a[j] == b[0] {
					has = true
					break
				}
			}
			if !has {
				fmt.Fprintln(out, "NO")
				return
			}
			break
		}
		cur--
	}
	fmt.Fprintln(out, "YES")
}

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var niter int
	fmt.Fscan(scanner, &niter)
outer:
	for iiter := 0; iiter < niter; iiter++ {
		var n, m int
		fmt.Fscan(scanner, &n, &m)
		var sa, sb string
		fmt.Fscan(scanner, &sa, &sb)
		for i := m - 1; i > 0; i-- {
			if sa[i+(n-m)] != sb[i] {
				fmt.Fprintln(writer, "No")
				continue outer
			}
		}
		target := sb[0]
		for i := 0; i <= n-m; i++ {
			if sa[i] == target {
				fmt.Fprintln(writer, "Yes")
				continue outer
			}
		}
		fmt.Fprintln(writer, "No")
	}
}

package main

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

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

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	var a, b string
	fmt.Fscan(rr, &a, &b)
	for i:=0;i<m-1;i++ {
		if a[n-i-1] != b[m-i-1] {
			fmt.Fprintln(ww, "NO")
			return
		}
	}
	for i:=0;i<=n-m;i++ {
		if a[i] == b[0] {
			fmt.Fprintln(ww, "YES")
			return
		}
	}
	fmt.Fprintln(ww, "NO")
}

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"
	"strconv"
	"strings"
)

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

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

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

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

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

/**
Run solve the problem CF1704A
Date: 10/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1704/A
Problem: CF1704A
**/
func (in *CF1704A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextInt()
		a := in.NextString()
		ones := 0
		for i := 0; i < n; i++ {
			if a[i] == '1' {
				ones++
			}
		}

		zeroes := 0
		b := in.NextString()
		for i := 0; i < m; i++ {
			if b[i] == '0' {
				zeroes++
			}
		}

		ans := true
		if m == 1 && ones-n > 0 {
			ans = true
		} else if m > n {
			ans = false
		} else if a[n-1] != b[m-1] {
			ans = false
		} else if a == "10" && b == "1" {
			ans = true
		} else {
			eq := 0
			for i, j := n-1, m-1; j >= 0 && i >= 0; {
				if a[i] == b[j] {
					eq++
					j--
					i--
				} else if eq == m-1 {
					i--
				} else {
					break
				}
			}
			if eq < m {
				ans = false
			}
		}

		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1704A
Date: 10/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1704/A
Problem: CF1704A
**/
func (in *CF1704A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextInt()
		a := in.NextString()
		ones := 0
		for i := 0; i < n; i++ {
			if a[i] == '1' {
				ones++
			}
		}

		zeroes := 0
		b := in.NextString()
		for i := 0; i < m; i++ {
			if b[i] == '0' {
				zeroes++
			}
		}

		ans := true
		if m == 1 && ones < n && n > 1 {
			ans = true
		} else if m > n {
			ans = false
		} else if a[n-1] != b[m-1] {
			ans = false
		} else if a == "10" && b == "1" {
			ans = true
		} else {
			eq := 0
			for i, j := n-1, m-1; j >= 0 && i >= 0; {
				if a[i] == b[j] {
					eq++
					j--
					i--
				} else if eq == m-1 {
					i--
				} else {
					break
				}
			}
			if eq < m {
				ans = false
			}
		}

		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1704A
Date: 10/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1704/A
Problem: CF1704A
**/
func (in *CF1704A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextInt()
		a := in.NextString()
		ones := 0
		for i := 0; i < n; i++ {
			if a[i] == '1' {
				ones++
			}
		}

		zeroes := 0
		b := in.NextString()
		for i := 0; i < m; i++ {
			if b[i] == '0' {
				zeroes++
			}
		}

		ans := true
		if m == 1 && ones < n {
			ans = true
		} else if m > n {
			ans = false
		} else if a[n-1] != b[m-1] {
			ans = false
		} else if a == "10" && b == "1" {
			ans = true
		} else {
			eq := 0
			for i, j := n-1, m-1; j >= 0 && i >= 0; {
				if a[i] == b[j] {
					eq++
					j--
					i--
				} else if eq == m-1 {
					i--
				} else {
					break
				}
			}
			if eq < m {
				ans = false
			}
		}

		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1704A
Date: 10/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1704/A
Problem: CF1704A
**/
func (in *CF1704A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextInt()
		a := in.NextString()
		b := in.NextString()

		ans := true
		if a == "10" && b == "1" {
			ans = true
		} else if m > n {
			ans = false
		} else if a[n-1] != b[m-1] {
			ans = false
		} else {
			eq := 0
			for i, j := n-1, m-1; j >= 0 && i >= 0; {
				if a[i] == b[j] {
					eq++
					j--
					i--
				} else if eq == m-1 {
					i--
				} else {
					break
				}
			}
			if eq < m {
				ans = false
			}
		}

		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1704A
Date: 10/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1704/A
Problem: CF1704A
**/
func (in *CF1704A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextInt()
		a := in.NextString()
		ones := 0
		for i := 0; i < n; i++ {
			if a[i] == '1' {
				ones++
			}
		}

		zeroes := 0
		b := in.NextString()
		for i := 0; i < m; i++ {
			if b[i] == '0' {
				zeroes++
			}
		}

		ans := true
		if m > n {
			ans = false
		} else if a[n-1] != b[m-1] {
			ans = false
		} else if a == "10" && b == "1" {
			ans = true
		} else {
			eq := 0
			for i, j := n-1, m-1; j >= 0 && i >= 0; {
				if a[i] == b[j] {
					eq++
					j--
					i--
				} else if eq == m-1 {
					i--
				} else {
					break
				}
			}
			if eq < m {
				ans = false
			}
		}

		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1704A
Date: 10/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1704/A
Problem: CF1704A
**/
func (in *CF1704A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m := in.NextInt(), in.NextInt()
		a := in.NextString()
		ones := 0
		for i := 0; i < n; i++ {
			if a[i] == '1' {
				ones++
			}
		}

		zeroes := 0
		b := in.NextString()
		for i := 0; i < m; i++ {
			if b[i] == '0' {
				zeroes++
			}
		}

		ans := true
		if m > n {
			ans = false
		} else if a[n-1] != b[m-1] {
			ans = false
		} else {
			eq := 0
			for i, j := n-1, m-1; j >= 0 && i >= 0; {
				if a[i] == b[j] {
					eq++
					j--
					i--
				} else if eq == m-1 {
					i--
				} else {
					break
				}
			}
			if eq < m {
				ans = false
			}
		}

		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

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

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

package main

import (
    "fmt"
    "strings"
)

func work(a, b string) bool {
    if len(b) > len(a) {
        return false
    }
    if a[len(a)-len(b):] == b {
        return true
    }
    if a[len(a)-len(b)+1:] != b[1:] {
        return false
    }
    return strings.Contains(a[0:len(a)-len(b)+1], b[0:1])
}

func main() {
        var t int
        fmt.Scanf("%d\n", &t)
        for ;t>0; t-- {
            var n, m int
            var a, b string
            fmt.Scanf("%d %d\n", &n, &m)
            fmt.Scanf("%s\n", &a)
            fmt.Scanf("%s\n", &b)

            if work(a, b) {
                    fmt.Printf("yes")
            } else {
                    fmt.Printf("no")
            }
        }
}

package main

import (
    "fmt"
    "strings"
)

func work(a, b string) bool {
    if len(b) > len(a) {
        return false
    }
    if a[len(a)-len(b):] == b {
        return true
    }
    if a[len(a)-len(b)+1:] != b[1:] {
        return false
    }
    return strings.Contains(a[0:len(a)-len(b)+1], b[0:1])
}

func main() {
        var t int
        fmt.Scanf("%d", &t)
        for ;t>0; t-- {
            var n, m int
            var a, b string
            fmt.Scanf("%d %d", &n, &m)
            fmt.Scanf("%s", &a)
            fmt.Scanf("%s", &b)

            if work(a, b) {
                    fmt.Printf("yes- %s %s\n", a,b)
            } else {
                    fmt.Printf("no - %s %s\n", a,b)
            }
        }
}

package main

import (
    "fmt"
    "strings"
)

func work(a, b string) bool {
    if len(b) > len(a) {
        return false
    }
    if a[len(a)-len(b):] == b {
        return true
    }
    if a[len(a)-len(b)+1:] != b[1:] {
        return false
    }
    return strings.Contains(a[0:len(a)-len(b)+1], b[0:1])
}

func main() {
        var t int
        fmt.Scanf("%d", &t)
        for ;t>0; t-- {
            var n, m int
            var a, b string
            fmt.Scanf("%d %d", &n, &m)
            fmt.Scanf("%s", &a)
            fmt.Scanf("%s", &b)

            if work(a, b) {
                fmt.Println("yes")
            } else {
                fmt.Println("no")
            }
        }
}

package main

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

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

func CF1704A(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 m, n int
		fmt.Fscan(r, &m, &n)
		var a, b []byte
		fmt.Fscan(r, &a, &b)

		if m == n {
			if bytes.Compare(a, b) == 0 {
				fmt.Fprintln(w, "YES")
			} else {
				fmt.Fprintln(w, "NO")
			}
			continue
		}

		// fmt.Fprintln(w, string(a[len(a)-n+1:]), " ", string(b[1:]))
		//fmt.Fprintln(w, string(a[:len(a)-n]), " ", string(b[:1]))
		if bytes.Compare(a[len(a)-n+1:], b[1:]) == 0 && bytes.Count(a[:len(a)-n], b[:1]) >= 1 {
			fmt.Fprintln(w, "YES")
			continue
		}
		fmt.Fprintln(w, "NO")
	}
}
func max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

package main

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

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

func CF1704A(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 m, n int
		fmt.Fscan(r, &m, &n)
		var a, b []byte
		fmt.Fscan(r, &a, &b)

		// fmt.Fprintln(w, string(a[len(a)-n+1:]), " ", string(b[1:]))
		//fmt.Fprintln(w, string(a[:len(a)-n]), " ", string(b[:1]))
		if bytes.Compare(a[len(a)-n+1:], b[1:]) == 0 && bytes.Count(a[:len(a)-n], b[:1]) >= 1 {
			fmt.Fprintln(w, "YES")
			continue
		}
		fmt.Fprintln(w, "NO")
	}
}
func max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}


You are given a picture consisting of $$$n$$$ rows and $$$m$$$ columns. Rows are numbered from $$$1$$$ to $$$n$$$ from the top to the bottom, columns are numbered from $$$1$$$ to $$$m$$$ from the left to the right. Each cell is painted either black or white. You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers $$$x$$$ and $$$y$$$, where $$$1 \le x \le n$$$ and $$$1 \le y \le m$$$, such that all cells in row $$$x$$$ and all cells in column $$$y$$$ are painted black.For examples, each of these pictures contain crosses:  The fourth picture contains 4 crosses: at $$$(1, 3)$$$, $$$(1, 5)$$$, $$$(3, 3)$$$ and $$$(3, 5)$$$.Following images don't contain crosses:  You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?You are also asked to answer multiple independent queries.

The first line contains an integer $$$q$$$ ($$$1 \le q \le 5 \cdot 10^4$$$) — the number of queries. The first line of each query contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 5 \cdot 10^4$$$, $$$n \cdot m \le 4 \cdot 10^5$$$) — the number of rows and the number of columns in the picture. Each of the next $$$n$$$ lines contains $$$m$$$ characters — '.' if the cell is painted white and '*' if the cell is painted black. It is guaranteed that $$$\sum n \le 5 \cdot 10^4$$$ and $$$\sum n \cdot m \le 4 \cdot 10^5$$$.

Print $$$q$$$ lines, the $$$i$$$-th line should contain a single integer — the answer to the $$$i$$$-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.

NoteThe example contains all the pictures from above in the same order.The first 5 pictures already contain a cross, thus you don't have to paint anything.You can paint $$$(1, 3)$$$, $$$(3, 1)$$$, $$$(5, 3)$$$ and $$$(3, 5)$$$ on the $$$6$$$-th picture to get a cross in $$$(3, 3)$$$. That'll take you $$$4$$$ minutes.You can paint $$$(1, 2)$$$ on the $$$7$$$-th picture to get a cross in $$$(4, 2)$$$.You can paint $$$(2, 2)$$$ on the $$$8$$$-th picture to get a cross in $$$(2, 2)$$$. You can, for example, paint $$$(1, 3)$$$, $$$(3, 1)$$$ and $$$(3, 3)$$$ to get a cross in $$$(3, 3)$$$ but that will take you $$$3$$$ minutes instead of $$$1$$$.There are 9 possible crosses you can get in minimum time on the $$$9$$$-th picture. One of them is in $$$(1, 1)$$$: paint $$$(1, 2)$$$ and $$$(2, 1)$$$.

package main

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

func main() {
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	defer write.Flush()
	var q int
	fmt.Fscan(read, &q)
	for iq := 0; iq < q; iq++ {
		var n, m int
		fmt.Fscan(read, &n, &m)
		var nsum = make([]int, n)
		var msum = make([]int, m)
		var a = make([][]bool, n)
		for i := 0; i < n; i++ {
			a[i] = make([]bool, m)
			var s string
			fmt.Fscan(read, &s)
			var lens = len(s)
			for j := 0; j < lens; j++ {
				if s[j] == 42 {
					a[i][j] = true
					nsum[i]++
					msum[j]++
				}
			}
		}

		var nsmax, msmax int
		for i := 0; i < n; i++ {
			if nsmax < nsum[i] {
				nsmax = nsum[i]
			}
			if nsmax == m {
				break
			}
		}
		for i := 0; i < m; i++ {
			if msmax < msum[i] {
				msmax = msum[i]
			}
			if msmax == n {
				break
			}
		}

		var res = n + m - msmax - nsmax
		if msmax == n || nsmax == m {
			fmt.Fprintln(write, res)
			continue
		}

		if msmax == 0 || nsmax == 0 {
			res--
			fmt.Fprintln(write, res)
			continue
		}

		var ns []int
		var ms []int
		for i := 0; i < n; i++ {
			if nsum[i] == nsmax {
				ns = append(ns, i)
			}
		}

		for i := 0; i < m; i++ {
			if msum[i] == msmax {
				ms = append(ms, i)
			}
		}
		var f bool
		for _, i := range ns {
			for _, j := range ms {
				if !a[i][j] {
					res--
					f = true
					break
				}
			}
			if f {
				break
			}
		}
		fmt.Fprintln(write, res)
	}
}

package main

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

func main() {
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	defer write.Flush()
	var q int
	fmt.Fscan(read, &q)
	for iq := 0; iq < q; iq++ {
		var n, m int
		fmt.Fscan(read, &n, &m)
		var nsum = make([]int, n)
		var msum = make([]int, m)
		var a = make([][]bool, n)
		for i := 0; i < n; i++ {
			a[i] = make([]bool, m)
			var s string
			fmt.Fscan(read, &s)
			var bufs = strings.Split(s, "")
			for j, v := range bufs {
				if v == "*" {
					a[i][j] = true
					nsum[i]++
					msum[j]++
				}
			}
		}

		var nsmax, msmax int
		for i := 0; i < n; i++ {
			if nsmax < nsum[i] {
				nsmax = nsum[i]
			}
			if nsmax == m {
				break
			}
		}
		for i := 0; i < m; i++ {
			if msmax < msum[i] {
				msmax = msum[i]
			}
			if msmax == n {
				break
			}
		}

		var res = n + m - msmax - nsmax
		if msmax == n || nsmax == m {
			fmt.Fprintln(write, res)
			continue
		}

		if msmax == 0 || nsmax == 0 {
			res--
			fmt.Fprintln(write, res)
			continue
		}

		var ns []int
		var ms []int
		for i := 0; i < n; i++ {
			if nsum[i] == nsmax {
				ns = append(ns, i)
			}
		}

		for i := 0; i < m; i++ {
			if msum[i] == msmax {
				ms = append(ms, i)
			}
		}
		var f bool
		for _, i := range ns {
			for _, j := range ms {
				if !a[i][j] {
					res--
					f = true
					break
				}
			}
			if f {
				break
			}
		}
		fmt.Fprintln(write, res)
	}
}

package main

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

func (io *IO) Solve_() int {
	n, m := io.Int(), io.Int()
	t := make([][]bool, n)
	rcount := make([]int, n)
	ccount := make([]int, m)
	for i := 0; i < n; i++ {
		t[i] = make([]bool, m)
		b := io.Bytes()
		for j, s := range b {
			if s == '*' {
				t[i][j] = true
				rcount[i]++
				ccount[j]++
			}
		}
	}
	rmax, cmax := 0, 0
	for i := 0; i < n; i++ {
		if rcount[i] > rmax {
			rmax = rcount[i]
		}
	}
	for j := 0; j < m; j++ {
		if ccount[j] > cmax {
			cmax = ccount[j]
		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if rcount[i] == rmax && ccount[j] == cmax && t[i][j] == false {
				return n + m - rmax - cmax - 1
			}
		}
	}
	return n + m - rmax - cmax
}

func (io *IO) Solve() {
	n := io.Int()
	for i := 0; i < n; i++ {
		io.Printf("%v\n", io.Solve_())
	}
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func (io *IO) UInt() (n uint) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + uint(v-'0')
	}
	return
}

func (io *IO) Bytes() []byte {
	io.scanner.Scan()
	return io.scanner.Bytes()
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) UIntArray(n int) (arr []uint) {
	arr = make([]uint, n)
	for i := 0; i < n; i++ {
		arr[i] = io.UInt()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}

package main

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

func (io *IO) Solve_() int {
	n, m := io.Int(), io.Int()
	t := make([][]bool, n)
	rcount := make([]int, n)
	ccount := make([]int, m)
	for i := 0; i < n; i++ {
		t[i] = make([]bool, m)
		b := io.Bytes()
		for j, s := range b {
			if s == '.' {
				t[i][j] = true
				rcount[i]++
				ccount[j]++
			}
		}
	}
	res := n + m
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			r := rcount[i] + ccount[j]
			if t[i][j] {
				r--
			}
			if r < res {
				res = r
			}
		}
	}
	return res
}

func (io *IO) Solve() {
	n := io.Int()
	for i := 0; i < n; i++ {
		io.Printf("%v\n", io.Solve_())
	}
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func (io *IO) UInt() (n uint) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + uint(v-'0')
	}
	return
}

func (io *IO) Bytes() []byte {
	io.scanner.Scan()
	return io.scanner.Bytes()
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) UIntArray(n int) (arr []uint) {
	arr = make([]uint, n)
	for i := 0; i < n; i++ {
		arr[i] = io.UInt()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}

package main

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

var  r, c [50001]int
var  flag [400010]bool

func main(){
   rr := NewScanner()
   T := rr.NextInt()
   for ;T >0; T--{
       	n, m := rr.NextInt(), rr.NextInt()
        for i := 0; i < n; i ++ {r[i] = 0}
        for i := 0; i < m; i ++ {c[i] = 0}
        for i := 0; i < n * m; i ++ {flag[i] = false}

        mat := make([][]byte, n)
        for i := 0; i < n; i ++{
        	mat[i] = []byte(rr.NextLine())
        }

        for i:= 0; i < n; i ++{
            for j := 0; j < m; j ++ {
            	if mat[i][j] == '*' {
                    flag[i * m + j] = true
                    r[i] ++
                    c[j] ++
                }
            }
        }
        ret := n + m - 1
        for i := 0; i < n; i ++{
            for j := 0; j < m; j ++{
                switch{
                    case flag[i * m + j] == true:
                         ret = int(math.Min(float64(ret), float64(n + m - r[i] - c[j])))
                    default:
                         ret = int(math.Min(float64(ret), float64(n + m - r[i] - c[j] - 1)))
                }
            }
        }
        fmt.Printf("%d\n", ret)
   }
   return
}

type Scanner struct{
	r   *bufio.Reader
	buf []byte
	p 	int
}

func NewScanner() *Scanner{
	return &Scanner{r: bufio.NewReaderSize(os.Stdin, 1024)}
}
func (s *Scanner) Next() string{
	s.pre()
	st := s.p
	for ; s.p < len(s.buf); s.p ++{
		if s.buf[s.p] == ' '{
			break
		}
	}
	res := string(s.buf[st: s.p])
	s.p ++
	return res
}
func (s *Scanner) NextLine() string{
	s.pre()
	st := s.p
	s.p = len(s.buf)
	return string(s.buf[st:])
}
func (s *Scanner) NextInt() int{
	ret, _ := strconv.Atoi(s.Next())
	return ret
}
func (s *Scanner) pre(){
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine(){
	s.buf = make([]byte, 0)
	for{
		l, p, e := s.r.ReadLine()
		if e != nil{
			panic(e)
		}
		s.buf = append(s.buf, l ...)
		if !p{
			break
		}
	}
}

package main

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

func main() {
	defer Flush()
	q := readi()
	for i := 0; i < q; i++ {
		n := readi()
		m := readi()
		f := make([][]byte, n)
		for i := range f {
			f[i] = readb()
		}
		println(solve(n, m, f))
	}

}

func solve(n, m int, f [][]byte) int {
	ys := make([]int, n)
	for i := range f {
		for j := range f[i] {
			if f[i][j] != '*' {
				ys[i]++
			}
		}
	}

	xs := make([]int, m)
	for j := range f[0] {
		for i := range f {
			if f[i][j] != '*' {
				xs[j]++
			}
		}
	}
	ans := n + m + 1
	for i := range f {
		for j := range f[i] {
			v := ys[i] + xs[j]
			if f[i][j] != '*' {
				v--
			}
			ans = min(ans, v)
		}
	}
	return ans
}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	for i := 0; i < N; i++ {
		A, B := sc.NextInt(), sc.NextInt()
		matrix := make([][]byte, A)
		for j := 0; j < A; j++ {
			matrix[j] = []byte(sc.NextLine())
		}

		rows := make([]map[int]bool, A)
		columns := make([]map[int]bool, B)

		for a := 0; a < A; a++ {
			rows[a] = map[int]bool{}
			for j := 0; j < B; j++ {
				if matrix[a][j] == '.' {
					rows[a][j] = true
				}
			}
		}

		for a := 0; a < B; a++ {
			columns[a] = map[int]bool{}
			for j := 0; j < A; j++ {
				if matrix[j][a] == '.' {
					columns[a][j] = true
				}
			}
		}
		mx := A * B
		for _, row := range rows {
			for j, column := range columns {
				cnt := len(row) + len(column)
				if row[j] {
					cnt--
				}
				mx = min(mx, cnt)
			}
		}
		fmt.Println(mx)
	}

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1194/problem/B

package main

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

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

func getColumnMinutes(column int, rows int, picture []string) int {
	minutes := 0
	for i := 0; i < rows; i++ {
		if string(picture[i][column]) == "." {
			minutes += 1
		}
	}
	return minutes
}

func getRowMinutes(row int, columns int, minColumns map[int]bool, picture []string) (int, bool) {
	minutes := 0
	hasMinColumn := false
	for i := 0; i < columns; i++ {
		if string(picture[row][i]) == "." {
			minutes += 1
		}
		if string(picture[row][i]) == "." && minColumns[i] {
			hasMinColumn = true
		}
	}
	return minutes, hasMinColumn
}

func Solve(n int, m int, picture []string) int {
	columnMinutesMap := make(map[int]int)
	minColumnMinutes := 1000000
	for column := 0; column < m; column++ {
		columnMinutesMap[column] = getColumnMinutes(column, n, picture)
		minColumnMinutes = min(minColumnMinutes, columnMinutesMap[column])
	}
	minColumns := make(map[int]bool)
	for key, value := range columnMinutesMap {
		if value == minColumnMinutes {
			minColumns[key] = true
		}
	}
	minMinutesNeeded := 1000000
	for row := 0; row < n; row++ {
		rowMinutes, hasMinColumn := getRowMinutes(row, m, minColumns, picture)
		if hasMinColumn {
			minMinutesNeeded = min(minMinutesNeeded, rowMinutes+minColumnMinutes-1)
		} else {
			minMinutesNeeded = min(minMinutesNeeded, rowMinutes+minColumnMinutes)
		}
	}
	return minMinutesNeeded
}

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Fscanf(reader, "%d %d\n", &n, &m)
		picture := make([]string, n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%s\n", &picture[j])
		}
		fmt.Fprintf(writer, "%d\n", Solve(n, m, picture))
	}
}

package main

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

func main() {
	//var read, _ = os.Open("dat.txt")
	//var write, _ = os.Create("result.txt")
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	defer write.Flush()
	var q int
	fmt.Fscan(read, &q)
	for iq := 0; iq < q; iq++ {
		var n, m int
		fmt.Fscan(read, &n, &m)
		var nsum = make([]int, n)
		var msum = make([]int, m)
		var a = make([][]bool, n)
		for i := 0; i < n; i++ {
			a[i] = make([]bool, m)
			var s string
			fmt.Fscan(read, &s)
			var bufs = strings.Split(s, "")
			for j, v := range bufs {
				if v == "*" {
					a[i][j] = true
					nsum[i]++
					msum[j]++
				}
			}
		}

		var nsmax, msmax int
		for i := 0; i < n; i++ {
			if nsmax < nsum[i] {
				nsmax = nsum[i]
			}
			if nsmax == m {
				break
			}
		}
		for i := 0; i < m; i++ {
			if msmax < msum[i] {
				msmax = msum[i]
			}
			if msmax == n {
				break
			}
		}

		var res = n + m - msmax - nsmax
		if msmax == n || nsmax == m {
			fmt.Fprintln(write, res)
			continue
		}

		if msmax == 0 || nsmax == 0 {
			res--
			fmt.Fprintln(write, res)
			continue
		}

		var ns []int
		var ms []int
		for i := 0; i < n; i++ {
			if nsum[i] == nsmax {
				ns = append(ns, i)
			}
		}

		for i := 0; i < m; i++ {
			if msum[i] == msmax {
				ms = append(ms, i)
			}
		}

		for _, i := range ns {
			for _, j := range ms {
				if !a[i][j] {
					res--
					break
				}
			}
		}
		fmt.Fprintln(write, res)
	}

	//read.Close()
	//write.Close()
}

package main

import (
    "fmt"
    "math"
)

var  r, c [50001]int

func main(){
   var T int
   var s string
   fmt.Scanf("%d\n", &T)
   for ;T >0; T--{
        var n, m int
        fmt.Scanf("%d%d\n", &n, &m)
        for i := 1; i <= n; i ++{
            r[i] = 0
        }
        for i := 1; i <= m; i ++{
            c[i] = 0
        }
        for i := 1; i <= n; i ++ {
            fmt.Scanf("%s\n", &s)
            for j := 1; j <= m; j ++{
                if s[j - 1] == '*'{
                   r[i], c[j] = r[i] + 1, c[j] + 1
                }
            }
        }
        ret := n + m - 1
        for i := 1; i <= n; i ++{
            for j := 1; j <= m; j ++{
                ret = int(math.Min(float64(ret), float64(n + m - r[i] - c[j])))
            }
        }
        fmt.Printf("%d\n", ret)
   }
   return
}