package main

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

// github.com/EndlessCheng/codeforces-go
func CF1154G(_r io.Reader, out io.Writer) {
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}

	id := [1e7 + 1]int{}
	min, x, y := int64(1e18), 0, 0
	n := r()
	for i := 1; i <= n; i++ {
		if v := r(); id[v] == 0 {
			id[v] = i
		} else if int64(v) < min {
			min, x, y = int64(v), id[v], i
		}
	}
	for i := 1; i <= 1e7; i++ {
		v := 0
		for j := i; j <= 1e7; j += i {
			if id[j] > 0 {
				if v > 0 {
					if l := int64(v) * int64(j) / int64(i); l < min {
						min, x, y = l, id[v], id[j]
					}
					break
				}
				v = j
			}
		}
	}
	if x > y {
		x, y = y, x
	}
	Fprint(out, x, y)
}

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

package main

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

type point struct {
	w1, w2 int
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	var v int
	mapp := make([]int,1e7+2)
	var maxv int
	mat := make([]int,n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d", &v)
		mat[i] = v
		mapp[v]++
		if maxv < v {
			maxv = v
		}
	}
	fmt.Fscanf(buf, "\n")
	var minlcm int64
	var ansx, ansy,pre int
	var ans1,ans2 int
	ansx = 0
	ansy = 0
	for i := 1; i <= maxv; i++ {
		pre = 0
		for j := i; j <= maxv; j += i {
			if mapp[j] > 0 {
			//	fmt.Printf("%d %d %d\n",item.w1,item.w2,j)
				if pre > 0 {
					if minlcm == 0 || minlcm > int64(j/i)*int64(pre) {
						minlcm = int64(j/i) * int64(pre)
						ans1 = pre
						ans2 = j
					}
					break
				} else if mapp[j] > 1 {
					if minlcm == 0 || minlcm > int64(j) {
						minlcm = int64(j)
						ans1 = j
						ans2 = ans1
					}
					break
				}
				pre = j
			}
		}
	}
	for i:= 1;i <= n;i++{
		if mat[i] == ans1||ans2 == mat[i]{
			if ansx==0{
				ansx = i
				if mat[i]==ans1{
					ans1 = -1
				}else{
					ans2 = -1
				}
			}else {
				ansy = i
				break
			}
		}
	}
//	fmt.Printf("%d\n",minlcm)
	if ansx < ansy {
		fmt.Printf("%d %d\n", ansx, ansy)
	} else {
		fmt.Printf("%d %d\n", ansy, ansx)
	}

}

package main

import (
	. "fmt"
	"io"
	"os"
	"runtime/debug"
)

// github.com/EndlessCheng/codeforces-go
func CF1154G(_r io.Reader, out io.Writer) {
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}

	id := [1e7 + 1]int{}
	min, x, y := int64(1e18), 0, 0
	n := r()
	for i := 1; i <= n; i++ {
		if v := r(); id[v] == 0 {
			id[v] = i
		} else if int64(v) < min {
			min, x, y = int64(v), id[v], i
		}
	}
	for i := 1; i <= 1e7; i++ {
		v := 0
		for j := i; j <= 1e7; j += i {
			if id[j] > 0 {
				if v > 0 {
					if l := int64(v) * int64(j) / int64(i); l < min {
						min, x, y = l, id[v], id[j]
					}
					break
				}
				v = j
			}
		}
	}
	if x > y {
		x, y = y, x
	}
	Fprint(out, x, y)
}

func main() {
	debug.SetGCPercent(-1)
	CF1154G(os.Stdin, os.Stdout)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1154G(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	id := [1e7 + 1]int{}
	min := int64(1e18)
	var n, v, x, y int
	Fscan(in, &n)
	for i := 1; i <= n; i++ {
		Fscan(in, &v)
		if id[v] == 0 {
			id[v] = i
		} else if int64(v) < min {
			min, x, y = int64(v), id[v], i
		}
	}
	for i := 1; i <= 1e7; i++ {
		v = 0
		for j := i; j <= 1e7; j += i {
			if id[j] > 0 {
				if v > 0 {
					if l := int64(v) * int64(j) / int64(i); l < min {
						min, x, y = l, id[v], id[j]
					}
					break
				}
				v = j
			}
		}
	}
	if x > y {
		x, y = y, x
	}
	Fprint(out, x, y)
}

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

package main

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

type point struct {
	w1, w2 int
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	var v int
	mapp := make(map[int]point)
	var maxv int
	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d", &v)
		item, ok := mapp[v]
		if ok {
			item.w2 = i
		} else {
			mapp[v] = point{
				w1: i,
			}
		}
		if maxv < v {
			maxv = v
		}
	}
	fmt.Fscanf(buf, "\n")
	var minlcm, pre int64
	var ansx, ansy, prew int
	ansx = 0
	ansy = 0
	for i := 1; i <= maxv; i++ {
		pre = 0
		for j := i; j <= maxv; j += i {
			if item, ok := mapp[j]; ok {
				if pre > 0 {
					if minlcm == 0 || minlcm > int64(j/i)*pre {
						minlcm = int64(j/i) * int64(pre)
						ansx = prew
						ansy = item.w1
						break
					}
				} else if item.w2 > 0 {
					if minlcm == 0 || minlcm > int64(j) {
						minlcm = int64(j)
						ansx = item.w1
						ansy = item.w2
						break
					}
				}
				pre = int64(j)
				prew = item.w1
			}
		}
	}
	if ansx < ansy{
		fmt.Printf("%d %d\n",ansx,ansy)
	}else{
		fmt.Printf("%d %d\n",ansy,ansx)
	}

}

package main

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

type point struct {
	w1, w2 int
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	var v int
	mapp := make(map[int]point)
	var maxv int
	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d", &v)
		item, ok := mapp[v]
		if ok {
			item.w2 = i
		} else {
			mapp[v] = point{
				w1: i,
			}
		}
		if maxv < v {
			maxv = v
		}
	}
	fmt.Fscanf(buf, "\n")
	var minlcm, pre int64
	var ansx, ansy, prew int
	ansx = 0
	ansy = 0
	for i := 1; i <= maxv; i++ {
		pre = 0
		for j := i; j <= maxv; j += i {
			if item, ok := mapp[j]; ok {
				if pre > 0 {
					if minlcm == 0 || minlcm > int64(j/i)*pre {
						minlcm = int64(j/i) * int64(pre)
						ansx = prew
						ansy = item.w1
						break
					}
				} else if item.w2 > 0 {
					if minlcm == 0 || minlcm > int64(j) {
						minlcm = int64(j)
						ansx = item.w1
						ansy = item.w2
						break
					}
				}
				pre = int64(j)
				prew = item.w1
			}
		}
	}
	fmt.Printf("%d %d\n",ansx,ansy)

}


// 271B-mic_rizal
package main

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

func main() {
    var num, a [1000010]int
    z := bufio.NewReader(os.Stdin)
    var i, j, n, m, v int
    l := 100005
    var x [505][505]int
    for i = 2; i <= l; i++ {
        a[i] = 0
    }
    i = 2
    cou := 0
    for i <= l {
        if a[i] == 0 {
            num[i] = 1
        }
        j = 2
        for i*j <= l {
            a[i*j] = 1
            j++
        }
        i++
    }
    num[1] = 0
    fmt.Scan(&n, &m)
    min := 10000007
    for i = 0; i < n; i++ {
        for j = 0; j < m; j++ {
            fmt.Fscan(z, &x[i][j])
        }
    }
    for i = 0; i < n; i++ {
        v = 0
        for j = 0; j < m; j++ {
            if num[x[i][j]] == 0 {
                cou = x[i][j]
                for num[cou] == 0 {
                    cou++
                    v++
                }
            }
        }
        min = int(math.Min(float64(min), float64(v)))
    }
    for i = 0; i < m; i++ {
        v = 0
        for j = 0; j < n; j++ {
            if num[x[j][i]] == 0 {
                cou = x[j][i]
                for num[cou] == 0 {
                    cou++
                    v++
                }
            }
        }
        min = int(math.Min(float64(min), float64(v)))
    }
    fmt.Println(min)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    f := make([]bool,100500)
    prime := make([]int,0,10000)
    for i := 2; i <= 100100; i++ {
        if !f[i] {
            prime = append(prime,i)
            a := int64(i)*int64(i)
            for a <= 100100 {
                f[a] = true
                a += int64(i)
            }
        }
    }
    var n,m int
    fmt.Scan(&n,&m)
    rows, cols := make([]int,n), make([]int,m)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            scanner.Scan()
            a, _ := strconv.Atoi(scanner.Text())
            l, r := 0, len(prime)
            for (r-l) > 1 {
                m := (l+r)/2
                if a < prime[m] {
                    r = m
                } else {
                    l = m
                }
            }
            if a > prime[l] { l++ }
            rows[i] += prime[l]-a
            cols[j] += prime[l]-a
        }
    }
    ans := 1000000000
    for i := 0; i < n; i++ {
        if ans > rows[i] { ans = rows[i] }
    }
    for i := 0; i < m; i++ {
        if ans > cols[i] { ans = cols[i] }
    }
    fmt.Println(ans)
}

package main

import "os"
import "bufio"
import "strconv"

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

func main(){
	var n, m int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	var p [100050]int
	var a [501][501]int
	ans := 1000000000
	temp := 0
	p[1] = 1
	for i:=2; i<100050; i++ {
		if p[i] == 0 {
			for j:=i+i; j<100050; j+=i {
				p[j] = 1
			}
		}
	}
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	m, _ = strconv.Atoi(r.Text())
	for i:=0; i<n; i++ {
		for j:=0; j<m; j++ {
			r.Scan()
			temp, _ = strconv.Atoi(r.Text())
			k := 0
			for p[temp+k] == 1 {
				k += 1
			}
			a[i][j] = k
		}
	}
	for i:=0; i<n; i++ {
		s := 0
		for j:=0; j<m; j++ {
			s += a[i][j]
		}
		ans = min(ans, s)
	}
	for j:=0; j<m; j++ {
		s := 0
		for i:=0; i<n; i++ {
			s += a[i][j]
		}
		ans = min(ans, s)
	}
	w.WriteString(strconv.Itoa(ans)+"\n")
	w.Flush()
}

package main

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

func main() {
	// file, _ := os.Open("input")
	file := os.Stdin
	reader := bufio.NewReader(file)
	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	a := make([][]int, n)
	count := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		count[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(reader, "%d", &a[i][j])
		}
		fmt.Fscanf(reader, "\n")
	}

	// Create Eratos Primes
	size := 200000
	eratos := make([]bool, size)
	for i := 0; i < size; i++ {
		eratos[i] = true
	}

	for i := 2; i < size; i++ {
		if eratos[i] {
			for j := 2; j*i < size; j++ {
				eratos[i*j] = false
			}
		}
	}

	var primes []int
	for i := 2; i < size; i++ {
		if eratos[i] {
			primes = append(primes, i)
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			nextPrimePos := sort.SearchInts(primes, a[i][j])
			if primes[nextPrimePos] != a[i][j] {
				count[i][j] = primes[nextPrimePos] - a[i][j]
			} else {
				count[i][j] = 0
			}
		}
	}

	result := math.MaxInt32
	for i := 0; i < n; i++ {
		counter := 0
		for j := 0; j < m; j++ {
			counter += count[i][j]
		}

		result = min(result, counter)
	}

	for j := 0; j < m; j++ {
		counter := 0
		for i := 0; i < n; i++ {
			counter += count[i][j]
		}

		result = min(result, counter)
	}

	fmt.Print(result)
}

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

	return b
}

package main

import "fmt"

func main() {
    f := make([]bool,100500)
    prime := make([]int,0,10000)
    for i := 2; i <= 100100; i++ {
        if !f[i] {
            prime = append(prime,i)
            a := int64(i)*int64(i)
            for a <= 100100 {
                f[a] = true
                a += int64(i)
            }
        }
    }
    var n,m,a int
    fmt.Scan(&n,&m)
    //rows, cols := make([]int,n), make([]int,m)
    for i := 0; i < n; i++ {
        for j := 0; j < m; j++ {
            fmt.Scan(&a)
            /*
            l := 0
            for ; (l < len(prime)) && (a > prime[l]); l++ {
            }
            /*
            l, r := 0, len(prime)
            for (r-l) > 1 {
                m := (l+r)/2
                if a < prime[m] {
                    r = m
                } else {
                    l = m
                }
            }
            if a > prime[l] { l++ }
            */
    //        rows[i] += a
    //        cols[j] += a
        }
    }
    ans := 1000000000
    /*
    for i := 0; i < n; i++ {
        if ans > rows[i] { ans = rows[i] }
    }
    for i := 0; i < m; i++ {
        if ans > cols[i] { ans = cols[i] }
    }
    */
    fmt.Println(ans)
}


/*
 * Created by Reverie
 * 2021.07.11
 * 02:23:13
 */

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

	solve := func(Case int) {
		var s string
		Fscan(in, &s)

		n := len(s)
		isValid := true
		for i := n - 1; i >= 0; i-- {
			if s[0] == 'a'+byte(i) {
				s = s[1:]
			} else if s[i] == 'a'+byte(i) {
				s = s[:i]
			} else {
				isValid = false
				break
			}
		}

		if isValid {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

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

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

package main

import "fmt"

// 代码相当易懂，不多说
func algo(s string) bool {
	length := len(s)
	for i := length - 1; i >= 0; i-- {
		expected_letter := byte('a' + i)
		if s[i] == expected_letter {
			s = s[:i]
		} else if s[0] == expected_letter {
			s = s[1:]
		} else {
			return false
		}
	}
	return true
}

func main() {
	num_case := 0
	fmt.Scan(&num_case)

	for i := 0; i < num_case; i++ {
		var s string
		fmt.Scan(&s)
		if algo(s) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func algo(s string) bool {
	length := len(s)
	for i := length - 1; i >= 0; i-- {
		expected_char := byte('a' + i)
		if s[i] == expected_char {
			s = s[:i]
		} else if s[0] == expected_char {
			s = s[1:]
		} else {
			return false
		}
	}
	return true
	// i, j := 0, len(s)-1

	// if j == 0 {
	// 	return s[j] == 'a'
	// }

	// for i < j {
	// 	expected_char := byte('a' + (j - i))
	// 	if s[i] < s[j] {
	// 		if s[j] != expected_char {
	// 			return false
	// 		}
	// 		if int(s[j]-s[j-1]) == 1 {
	// 			j -= 2
	// 		} else if int(s[j]-s[i]) == 1 {
	// 			i++
	// 			j--
	// 		} else {
	// 			return false
	// 		}
	// 	} else if s[i] > s[j] {
	// 		if s[i] != expected_char {
	// 			return false
	// 		}
	// 		if int(s[i]-s[i+1]) == 1 {
	// 			i += 2
	// 		} else if int(s[i]-s[j]) == 1 {
	// 			i++
	// 			j--
	// 		} else {
	// 			return false
	// 		}
	// 	} else {
	// 		return false
	// 	}
	// }

	// return true
}

func input() []string {
	num_case := 0
	fmt.Scan(&num_case)
	testcases := make([]string, num_case)

	for i := 0; i < num_case; i++ {
		fmt.Scan(&testcases[i])
	}

	return testcases
}

func main() {
	strs := input()

	for _, s := range strs {
		if algo(s) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

type Point struct {
	x, y int
}

func main() {
	T := 0
	fmt.Scanf("%d\n", &T)
	for ; T > 0; T-- {
		var s string
		fmt.Scanf("%s\n", &s)

		n := len(s)
		isValid := true
		for i := n - 1; i >= 0; i-- {
			if s[0] == 'a'+byte(i) {
				s = s[1:]
			} else if s[i] == 'a'+byte(i) {
				s = s[:i]
			} else {
				isValid = false
				break
			}
		}

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

package main

import (
	"fmt"
)

func solve() {

	var s string
	fmt.Scan(&s)
	n := len(s)
	left := 0
	right := n - 1
	var max byte
	if s[left] > s[right] {
		max = s[left]
	} else {
		max = s[right]
	}
	if int(max-'a') != (n - 1) {
		fmt.Println("NO")
		return
	}
	for left <= right {
		if s[left] == max {
			max--
			left++
		} else if s[right] == max {
			max--
			right--
		} else {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")

}

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		solve()
		t--
	}

}

package main

import (
	"fmt"
)

func solve() {

	var s string
	fmt.Scan(&s)
	in := -1
	for i := range s {
		if s[i] == 'a' {
			in = i
			break
		}
	}
	if in == -1 {
		fmt.Println("NO")
	} else {
		left := in - 1
		right := in + 1
		n := len(s)
		var ch byte = 1
		for left >= 0 && right < n {
			if s[left]-'a' == ch {
				left--
				ch++
			} else if s[right]-'a' == ch {
				right++
				ch++
			} else {
				break
			}
		}
		for left >= 0 {
			if s[left]-'a' == ch {
				left--
				ch++
			} else {
				break
			}
		}
		for right < n {
			if s[right]-'a' == ch {
				right++
				ch++
			} else {
				break
			}
		}
		if left == -1 && right == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		solve()
		t--
	}

}

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

		f := true
		arr := make([]int, len(s))
		z := (len(s) - 1) * (len(s)) / 2
		m := make([]bool, 26)
		var seen bool
		for i, ch := range s {
			arr[i] = int(ch - 'a')
			z -= int(ch - 'a')

			if m[int(ch-'a')] {
				f = false
				break
			} else if !seen && ch == 'a' {
				seen = true
			} else if !seen && i > 0 {
				if arr[i-1] <= arr[i] {
					f = false
					break
				}
			} else if seen {
				if arr[i-1] >= arr[i] {
					f = false
					break
				}
			}
			m[int(ch-'a')] = true
		}

		if !f || z != 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

import (
	"fmt"
)

func solve() {
	var s string
	fmt.Scan(&s)
	length := len(s)
	pos := -1
	for i := 0; i < length; i++ {
		if s[i] == 'a' {
			pos = i
		}
	}
	if pos == -1 {
		fmt.Println("NO")
	} else {
		L := pos - 1
		R := pos + 1
		for i := 1; i < length; i++ {
			if L >= 0 && int(s[L]) == 'a'+i {
				L--
			} else if R < length && int(s[R]) == 'a'+i {
				R++
			} else {
				fmt.Println("NO")
				return
			}
		}
		fmt.Println("YES")
	}
}

func main() {
	// fmt.Println("Enter how much number")
	var t int
	// fmt.Scanf("%d", &t)
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

func solve(r io.Reader) {
	var n int
	var s string

	abc := "abcdefghijklmnopqrstuvwxyz"
	m := make(map[string]int)
	for i, r := range abc {
		c := string(r)
		m[c] = i + 1
	}

	reader := bufio.NewReader(r)
	s, _ = reader.ReadString('\n')
	s = strings.TrimSpace(s)
	n, _ = strconv.Atoi(s)

	for i := 0; i < n; i++ {
		s, _ = reader.ReadString('\n')
		s = strings.TrimSpace(s)
		prev_j := -1
		res := 0
		b := make([]int, len(abc))
		for j := 0; j < len(abc); j++ {
			b[j] = 1
		}

		for _, r := range s {
			c := string(r)
			if prev_j != -1 {
				if m[c] < prev_j {
					if res == 1 {
						res = -1
						break
					}
					res = 0
				} else {
					res = 1
				}
			}
			prev_j = m[c]
			b[m[c]-1] = 0
		}

		sum := 0
		for j := 0; j < len(s); j++ {
			sum += b[j]
		}

		if res != -1 && sum == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func main() {
	solve(os.Stdin)
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
var letters = map[string]int{
	"a": 1,
	"b": 2,
	"c": 3,
	"d": 4,
	"e": 5,
	"f": 6,
	"g": 7,
	"h": 8,
	"i": 9,
	"j": 10,
	"k": 11,
	"l": 12,
	"m": 13,
	"n": 14,
	"o": 15,
	"p": 16,
	"q": 17,
	"r": 18,
	"s": 19,
	"t": 20,
	"u": 21,
	"v": 22,
	"w": 23,
	"x": 24,
	"y": 25,
	"z": 26,
}

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 word string
		fmt.Fscan(in,&word)
		list:= make([]int,len(word))
		for j:=0;j<len(word);j++{
			list[j]= letters[string(word[j])]
		}
		indice:=0
		for j:=1;j<=len(list);j++{
			counter:=0
			for k:=1;k<=len(list);k++{
				if list[k-1] == j {
					counter++
				}
			}
			if counter == 0 || counter >= 2 {
				fmt.Fprintln(out,"NO")
				goto out
			}
		}
		for j:=0;j<len(list);j++{
			if list[j] == 1 {
				indice= j
				break
			} else {
				if j == len(list)-1 {
					fmt.Fprintln(out,"NO")
					goto out
				} else {
					if list[j] <= list[j+1] {
						fmt.Fprintln(out,"NO")
						goto out
					}
				}
			}
		}
		for j:=indice;j<len(list)-1;j++{
			if list[j] >= list[j+1] {
				fmt.Fprintln(out,"NO")
				goto out
			}
		}
		fmt.Fprintln(out,"YES")
		out:
	}
}

package main

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

type ele struct {
	v   rune
	ind int
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		s, o, ok := "", []ele{}, true
		fmt.Fscan(f, &s)
		for j := 0; j < len(s); j++ {
			o = append(o, ele{v: rune(s[j]), ind: j})
		}
		sort.Slice(o, func(i, j int) bool { return o[i].v < o[j].v })
		l, r, first := 0, 0, rune(97)
		for j := 0; j < len(o); j++ {
			if j == 0 {
				l, r, ok = o[j].ind, o[j].ind, o[j].v == first
			} else {
				if o[j].v != first+rune(j) || !(o[j].ind == l-1 || o[j].ind == r+1) {
					ok = false
				}
				if o[j].ind == l-1 {
					l = l - 1
				}
				if o[j].ind == r+1 {
					r = r + 1
				}
			}
		}
		if ok {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	s      string
)

func solve(s string) string {
	l := len(s)
	p := 0
	q := l - 1
	for i := 'a' + byte(l-1); i >= 'a'; i-- {
		if s[p] != i && s[q] != i {
			return "NO"
		}
		if s[p] == i {
			p++
		}
		if s[q] == i {
			q--
		}
	}
	return "YES"
}

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

package main

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

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

func (in *CF1547B) 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 *CF1547B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1547B
Date: 18/11/21
User: pepradere
URL: https://codeforces.com/problemset/problem/1547/B
Problem: CF1547B
**/
func (in *CF1547B) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		str := in.NextString()
		index := strings.Index(str, "a")
		ans := true
		if index == -1 {
			ans = false
		} else {
			letter := uint8('b')

			for left, right := index-1, index+1; ans ; letter++ {
				if left >= 0 {
					if str[left] == letter {
						left--
						continue
					}
				}
				if right < len(str) {
					if str[right] == letter {
						right++
						continue
					}
				}
				if left < 0 && right >= len(str){
					break
				}
				ans = false
			}
		}

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

	}
}

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

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

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 s string
		Fscan(in, &s)

		a := -1
		for i, c := range s {
			if c == 'a' {
				a = i
				break
			}
		}
		if a == -1 {
			Fprintln(out, "NO")
			continue
		}

		head, tail, curr, flag := a-1, a+1, a, true
		for head != -1 || tail != len(s) {
			if head != -1 && s[head] == s[curr] + 1 {
				curr = head; head--
			} else if tail != len(s) && s[tail] == s[curr] + 1 {
				curr = tail; tail++
			} else {
				Fprintln(out, "NO")
				flag = false
				break
			}
		}
		if flag {
			Fprintln(out, "YES")
		}
	}

}

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

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

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

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

package main

import "fmt"

var t int

func main() {
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var s string
		var l, r uint8

		fmt.Scan(&s)

		length := uint8(len(s))
		l = 0
		r = length-1
		for ; length > 0; length-- {
			if s[l] == length+96 {
				l++
			} else if s[r] == length+96 {
				r--
			} else {
				fmt.Println("NO")
				break
			}
		}

		if length == 0 { fmt.Println("YES") }
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var T int
	fmt.Fscan(os.Stdin,&T)
	for (T>0) {
		T--
		var s string
		fmt.Fscan(os.Stdin,&s)
		buff:=[]byte(s)
		length := len(buff)
		ok:=true
		for i:=length-1;i>=0;i-- {
			if( int(buff[len(buff)-1])==('a'+i)) {
				buff=buff[:len(buff)-1]
			}else if(int(buff[0])=='a'+i) {
				buff=buff[1:]
			}else {
				ok=false
			}
		}
		if (ok) {
			fmt.Println("YES")
		}else {
			fmt.Println("NO")
		}
	}
}

package main

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

const MOD = 1000000007

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

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

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

	for tc := 1; tc <= t; tc++ {
		solveTest(tc)
	}

	out.Flush()
}

func solveTest(tc int) {
	var s string
	fmt.Fscan(in, &s)

	if isAlphabetical(s) {
		fmt.Fprintln(out, "YES")
	} else {
		fmt.Fprintln(out, "NO")
	}
}

func isAlphabetical(s string) bool {
	n := len(s)
	if n == 0 {
		return true
	}

	c := rune(n - 1 + int('a'))
	if rune(s[0]) == c {
		return isAlphabetical(s[1:])
	} else if rune(s[n - 1]) == c {
		return isAlphabetical(s[0:n - 1])
	}
	return false
}

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

func min(xs ...int) int {
	result := xs[0]
	for i := 1; i < len(xs); i++ {
		if result > xs[i] {
			result = xs[i]
		}
	}
	return result
}

func max(xs ...int) int {
	result := xs[0]
	for i := 1; i < len(xs); i++ {
		if result < xs[i] {
			result = xs[i]
		}
	}
	return result
}

package main

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

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

	var tcs int
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var s string
		_, _ = fmt.Fscan(in, &s)

		ans := true
		for i, n, j := 0, len(s), len(s)-1; i <= j; n-- {
			x, y := int(s[i])-int('a'), int(s[j])-int('a')

			if n-1 == x {
				i++
			} else if n-1 == y {
				j--
			} else {
				ans = false
				break
			}
		}

		if ans {
			_, _ = fmt.Fprintln(out, "YES")
		} else {
			_, _ = fmt.Fprintln(out, "NO")
		}
	}

	_ = out.Flush()
}

func abs(n int) int {
	if n < 0 {
		n = -n
	}

	return n
}

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

	return b
}

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

	return b
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	fmt.Fprint(io.out, v...)
}

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

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	some: for t := io.ReadInt(); t > 0; t-- {
		s := io.ReadString()
		in := -1
		for i := range s {
			if s[i] == 'a' {
				in = i
			}
		}
		if in == -1 {
			io.Println("NO")
			continue
		}

		n := len(s)
		l, r := 1, 1

		for i := 1; i < n; i++ {
			if in-l >= 0 && s[in-l] == byte(int('a')+i) {
				l++
			} else if in+r < n && s[in+r] == byte(int('a')+i) {
				r++
			} else {
				io.Println("NO")
				continue some
			}
		}

		io.Println("YES")
	}
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		printf("%s\n", sol(sstring()))
	}
}

func sol(s string) string {
	aPos := findA(s)
	if aPos == -1 {
		return "NO"
	}
	for i := aPos + 1; i < len(s); i++ {
		if s[i-1] >= s[i] {
			return "NO"
		}
	}
	for i := aPos - 1; i >= 0; i-- {
		if s[i] <= s[i+1] {
			return "NO"
		}
	}
	letters := []rune(s)
	sort.Slice(letters, func(il, ir int) bool {
		return letters[il] < letters[ir]
	})
	for i := range letters {
		if letters[i] != rune('a')+rune(i) {
			return "NO"
		}
	}
	return "YES"
}

func findA(s string) int {
	for i := range s {
		if s[i] == 'a' {
			return i
		}
	}
	return -1
}

package main

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

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

	solve := func(Case int) (_b bool) {
		var s []byte
		Fscan(in, &s)
		n := len(s)
		cur := byte('a'+n-1)
		for len(s) >0 {
			if s[0] == cur {
				s = s[1:]
			} else if s[len(s)-1] == cur {
				s = s[:len(s)-1]
			} else {
				return false
			}
			cur--
		}
		return true
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		if solve(Case) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

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

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

package main

import "fmt"

func algo(s string) bool {
	i, j := 0, len(s)-1

	if j == 0 {
		return s[j] == 'a'
	}

	for i < j {
		expected_char := byte('a' + (j - i))
		if s[i] < s[j] {
			if s[j] != expected_char {
				return false
			}
			if int(s[j]-s[j-1]) == 1 {
				j -= 2
			} else if int(s[j]-s[i]) == 1 {
				i++
				j--
			} else {
				return false
			}
		} else if s[i] > s[j] {
			if s[i] != expected_char {
				return false
			}
			if int(s[i]-s[i+1]) == 1 {
				i += 2
			} else if int(s[i]-s[j]) == 1 {
				i++
				j--
			} else {
				return false
			}
		} else {
			return false
		}
	}

	return true
}

func input() []string {
	num_case := 0
	fmt.Scan(&num_case)
	testcases := make([]string, num_case)

	for i := 0; i < num_case; i++ {
		fmt.Scan(&testcases[i])
	}

	return testcases
}

func main() {
	strs := input()

	for _, s := range strs {
		if algo(s) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func algo(s string) bool {
	i, j := 0, len(s)-1
	for i < j {
		expected_char := byte('a' + (j - i))
		if s[i] < s[j] {
			if s[j] != expected_char {
				return false
			}
			if int(s[j]-s[j-1]) == 1 {
				j -= 2
			} else if int(s[j]-s[i]) == 1 {
				i++
				j--
			} else {
				return false
			}
		} else if s[i] > s[j] {
			if s[i] != expected_char {
				return false
			}
			if int(s[i]-s[i+1]) == 1 {
				i += 2
			} else if int(s[i]-s[j]) == 1 {
				i++
				j--
			} else {
				return false
			}
		} else {
			return false
		}
	}

	if i == len(s) || s[i] == 'a' {
		return true
	} else {
		return false
	}
}

func input() []string {
	num_case := 0
	fmt.Scan(&num_case)
	testcases := make([]string, num_case)

	for i := 0; i < num_case; i++ {
		fmt.Scan(&testcases[i])
	}

	return testcases
}

func main() {
	strs := input()
	for _, s := range strs {
		if algo(s) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func algo(s string) bool {
	i, j := 0, len(s)-1
	for i < j {
		if s[i] < s[j] {
			if int(s[j]-s[j-1]) == 1 {
				j -= 2
			} else if int(s[j]-s[i]) == 1 {
				i++
				j--
			} else {
				return false
			}
		} else if s[i] > s[j] {
			if int(s[i]-s[i+1]) == 1 {
				i += 2
			} else if int(s[i]-s[j]) == 1 {
				i++
				j--
			} else {
				return false
			}
		} else {
			return false
		}
	}

	if i == len(s) || s[i] == 'a' {
		return true
	} else {
		return false
	}
}

func input() []string {
	num_case := 0
	fmt.Scan(&num_case)
	testcases := make([]string, num_case)

	for i := 0; i < num_case; i++ {
		fmt.Scan(&testcases[i])
	}

	return testcases
}

func main() {
	strs := input()
	for _, s := range strs {
		if algo(s) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

/*
 * Created by Reverie
 * 2021.07.11
 * 02:23:13
 */

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

	solve := func(Case int) {
		var s string
		Scan(&s)

		n := len(s)
		isValid := true
		for i := n - 1; i >= 0; i-- {
			if s[0] == 'a'+byte(i) {
				s = s[1:]
			} else if s[i] == 'a'+byte(i) {
				s = s[:i]
			} else {
				isValid = false
				break
			}
		}

		if isValid {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

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

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

/*
 * Created by Reverie
 * 2021.07.11
 * 02:20:12
 */

package main

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

type Point struct {
	x, y int
}

func abs(x int) int {
	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()

	solve := func(Case int) {
		var a, b, f Point
		Fscan(in, &a.x, &a.y, &b.x, &b.y, &f.x, &f.y)

		ans := 0
		if a.x == b.x {
			if a.y > b.y {
				a.y, b.y = b.y, a.y
			}
			ans = b.y - a.y
			if f.x == a.x && f.y > a.y && f.y < b.y {
				ans += 2
			}
		} else if a.y == b.y {
			if a.x > b.x {
				a.x, b.x = b.x, a.x
			}
			ans = b.x - a.x
			if f.y == a.y && f.x > a.x && f.x < b.x {
				ans += 2
			}
		} else {
			ans = abs(a.x-b.x) + abs(a.y-b.y)
		}
		Fprintln(out, ans)
	}

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

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

package main

import (
	"fmt"
)

func solve() {

	var s string
	fmt.Scan(&s)
	n := len(s)
	left := 0
	right := n - 1
	var max byte
	if s[left] > s[right] {
		max = s[left]
	} else {
		max = s[right]
	}
	if int(max-'a') != (n - 1) {
		fmt.Println("NO")
		return
	}
	for left < right {
		if s[left] == max {
			max--
			left++
		} else if s[right] == max {
			max--
			right--
		} else {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")

}

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		solve()
		t--
	}

}

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

		f := true
		arr := make([]int, len(s))
		z := (len(s) - 1) * (len(s)) / 2
		var seen bool
		for i, ch := range s {
			arr[i] = int(ch - 'a')
			z -= int(ch - 'a')

			if !seen && ch == 'a' {
				seen = true
			} else if !seen && i > 0 {
				if arr[i-1] <= arr[i] {
					f = false
					break
				}
			} else if seen {
				if arr[i-1] >= arr[i] {
					f = false
					break
				}
			}
		}

		if !f || z != 0 {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

func solve(r io.Reader) {
	var n int
	var s string

	abc := "abcdefghijklmnopqrstuvwxyz"
	m := make(map[string]int)
	for i, r := range abc {
		c := string(r)
		m[c] = i + 1
	}

	reader := bufio.NewReader(r)
	s, _ = reader.ReadString('\n')
	s = strings.TrimSpace(s)
	n, _ = strconv.Atoi(s)

	for i := 0; i < n; i++ {
		s, _ = reader.ReadString('\n')
		s = strings.TrimSpace(s)
		prev_j := -1
		res := 0
		length := len(s)
		sum := (1 + length) * length / 2
		for _, r := range s {
			c := string(r)
			if prev_j != -1 {
				if m[c] < prev_j {
					if res == 1 {
						res = -1
						break
					}
					res = 0
				} else {
					res = 1
				}
			}
			prev_j = m[c]
			sum -= m[c]
		}
		if res != -1 && sum == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func main() {
	solve(os.Stdin)
}


package main

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

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

	tc := int32(0)
	fmt.Fscan(in, &tc)

	for ; tc > 0; tc-- {
		n := int32(0)
		fmt.Fscan(in, &n)

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

		if arr[0] == 1 {
			fmt.Fprintf(out, "yes\n")
		} else {
			fmt.Fprintf(out, "no\n")
		}
	}

	out.Flush()
}

package main

import (
	"fmt"
)

var eps float64 = 1e-4

func sq_root(n float64) float64 {
	var l, r float64 = 0, n
	m := (r + l) / 2

	for (r - l) > eps {
		m = (r + l) / 2
		if m*m > n {
			r = m
		} else {
			l = m
		}
	}
	return l
}

func main() {
	t := 0
	fmt.Scan(&t)
	for ; t > 0; t-- {
		n := 0
		fmt.Scan(&n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
		}
		if a[0] == 1 {
			fmt.Print("YES\n")
		} else {
			fmt.Print("NO\n")
		}
	}
}

package main

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

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

func (in *CF1750A) 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 *CF1750A) load() {
  if len(in.split) <= in.index {
    in.split = strings.Split(in.GetLine(), in.separator)
    in.index = 0
  }
}

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

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

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

/**
Run solve the problem CF1750A
Date: 11/15/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1750/A
Problem: CF1750A
**/
func (in *CF1750A) Run() {
  for t := in.NextInt(); t > 0; t-- {
    n := in.NextInt()
    min := -1
    f := -1
    for i := 0; i < n; i++ {
      val := in.NextInt()
      if f == -1 {
        f = val
      }
      if min == -1 {
        min = val
      } else if min > val {
        min = val
      }
    }

    if f == min {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }

  }
}

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

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

package main

import "fmt"

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

	for test > 0 {
		solve()
		test = test - 1
	}
}

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

	if first == 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import (
	"fmt"
	"sort"
)

func solve(e []int, n int) bool {
	fmt.Println(e)
	s := sort.IntsAreSorted(e)
	if s {
		return true
	}
	for i := n - 3; i >= 0; i-- {
		for j := i + 1; j < n; j++ {
			for k := j + 1; k < n; k++ {
				if e[i] > e[k] {
					e[i] = e[i] + e[j]
				} else {
					e[j], e[k] = e[k], e[j]
				}
				fmt.Println(i+1, j+1, k+1, e)
				s := sort.IntsAreSorted(e)
				if s {
					return true
				}
			}
		}
	}

	s = sort.IntsAreSorted(e)
	return s
}

func main() {
	var t, n int
	fmt.Scan(&t)
	for c := 0; c < t; c++ {
		var e []int
		fmt.Scan(&n)
		for i := 0; i < n; i++ {
			var x int
			fmt.Scan(&x)
			e = append(e, x)
		}

		s := e[0] == 1
		if s {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	_ = readInt(reader)
	a := readArrayInt(reader)
	if a[0] == 1 {
		fmt.Fprintln(writer, "Yes")
	} else {
		fmt.Fprintln(writer, "No")
	}
}

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		solve(reader, writer)
		t--
	}

	writer.Flush()
}

func min[T int | int64](a, b T) T {
	if a < b {
		return a
	}

	return b
}

func max[T int | int64](a, b T) T {
	if a > b {
		return a
	}

	return b
}

func abs[T int | int64](a T) T {
	if a < 0 {
		return a * -1
	} else {
		return a
	}
}

func gcd[T int | int64](x, y T) T {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm[T int | int64](x, y T) T {
	return x * y / gcd(x, y)
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 32)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

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

const (
	DEBUG = false
)

func debug(a ...interface{}) {
	if !DEBUG {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func debugCondn(condn bool, a ...interface{}) {
	if !DEBUG || !condn {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func assert(condn bool) {
	if !condn {
		panic("assertion error")
	}
}

func solve(tt int) {
	var n int
	scanf("%d\n", &n)
	a := make([]int, n)
	for i:=0; i<n; i++ {
		scanf("%d ", &a[i])
	}
	scanf("\n")

	if a[0] == 1 {
		printf("Yes\n")
		return
	}
	printf("No\n")
}

func main() {
	defer writer.Flush()

	var T int
	scanf("%d\n", &T)
	for tt:=1; tt<=T; tt++ {
		// printf("Case #%d: ", tt)
		solve(tt)
	}
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, u int
		fmt.Fscan(r, &n)

		res := "NO"
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &u)
			if i == 0 && u == 1 {
				res = "YES"
			}
		}

		fmt.Fprintln(w, res)
	}

}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	mn := n + 1
	for i := range arr {
		fmt.Fscan(in, &arr[i])
		mn = min(mn, arr[i])
	}
	if mn != arr[0] {
		fmt.Fprintln(out, "No")
	} else {
		fmt.Fprintln(out, "Yes")
	}
}

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

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

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

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

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

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

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

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		line := readNNums(reader, 4)
		n, m, a, b := line[0], line[1], line[2], line[3]
		ok, g := solve(n, m, a, b)
		if ok {
			fmt.Println("YES")
			for i := 0; i < n; i++ {
				fmt.Println(string(g[i]))
			}
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(n, m, a, b int) (bool, [][]byte) {
	if n*a != b*m {
		return false, nil
	}

	G := make([][]byte, n)
	var d = 1
	for (d*n)%m != 0 {
		d++
	}

	var j int
	for i := 0; i < n; i++ {
		G[i] = make([]byte, m)
		var x int
		for k := 0; k < m; k++ {
			if x < a {
				G[i][(j+k)%m] = '1'
				x++
			} else {
				G[i][(j+k)%m] = '0'
			}
		}
		j = (j + d) % m
	}

	return true, G
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)

	for tt := rd(); tt > 0; tt-- {
		n, m, a, b := rd(), rd(), rd(), rd()
		if n*a != b*m {
			Fprintln(out, "NO")
			continue
		}
		ans := make([][]int, n)
		c := 0
		for i := 0; i < n; i++ {
			ans[i] = make([]int, m)
			for j := 0; j < a; j++ {
				ans[i][c] = 1
				c = (c + 1) % m
			}
		}
		Fprintln(out, "YES")
		for _, i := range ans {
			for _, j := range i {
				Fprint(out, j)
			}
			Fprintln(out)
		}
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}

package main

import (
	"fmt"
)

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n, m, a, b int
		fmt.Scan(&n, &m, &a, &b)
		if n*a != m*b {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			G := make([][] rune, n)
			ctr := make([]int, m)
			cols := make([]int, m)
			for j := 0; j < m; j++ {
				cols[j] = j
			}
			for i := 0; i < n; i++ {
				G[i] = make([]rune, m)
				for j := 0; j < m; j++ {
					G[i][j] = '0'
				}

				for k := 0; k < m; k++ {
					q := k
					for q > 0 && ctr[cols[q-1]] > ctr[cols[q]] {
						a := cols[q-1]
						b := cols[q]
						cols[q-1] = b
						cols[q] = a
						q--
					}
				}

				for k := 0; k < a; k++ {
					j := cols[k]
					ctr[j]++
					G[i][j] = '1'
				}
				// fmt.Println(cols)
				// fmt.Println(ctr)
				fmt.Println(string(G[i]))
			}
		}
	}

}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

func (impl *wordScannerImpl) NextUInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

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

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

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

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

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

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n := reader.NextInt64()
		m := reader.NextInt64()
		a := reader.NextInt64()
		b := reader.NextInt64()
		res := sol(n, m, a, b)
		if res == nil {
			writer.Printf("NO\n")
		} else {
			writer.Printf("YES\n")
			for _, r := range res {
				writer.Printf("%s\n", string(r))
			}
		}
	}
}

func sol(n, m, a, b int64) [][]rune {
	// n rows, m cols
	// b corresponds to n
	// a corresponds to m
	if n * a != m * b {
		return nil
	}
	ret := make([][]rune, n)
	for i := range ret {
		ret[i] = make([]rune, m)
		for j := range ret[i] {
			ret[i][j] = '0'
		}
	}
	xpos := int64(0)
	for i := range ret {
		for j := int64(0); j < a; j++ {
			ret[i][xpos] = '1'
			xpos++
			xpos%=m
		}
	}
	return ret
}

/*
URL:
https://codeforces.com/contest/1360/problem/G
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, m int
	a, b int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m, a, b = ReadInt4()
		solve(n, m, a, b)
	}
}

func solve(n, m, a, b int) {
	if n*a != m*b {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")

	A := make([][]rune, n)
	for i := 0; i < n; i++ {
		A[i] = make([]rune, m)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			A[i][j] = '0'
		}
	}

	p := 0
	for i := 0; i < n; i++ {
		for j := 0; j < a; j++ {
			A[i][p%m] = '1'
			p++
		}
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	gcd := func(a, b int) int {
		for a != 0 {
			a, b = b%a, a
		}
		return b
	}

	var t, n, m, a, b int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b)
		if n*a != m*b {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		g := gcd(m, a)
		for i := 0; i < n; i++ {
			ans := make([]byte, m)
			for j := range ans {
				ans[j] = '0'
			}
			for c := 0; c < a; c++ {
				ans[(g*i+c)%m] = '1'
			}
			Fprintln(out, string(ans))
		}
	}
}

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

package main

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

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

	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	type edge struct{ to, rev, cap int }

	solve := func(_case int) {
		var n, m, a, b, maxFlow int
		Fscan(in, &n, &m, &a, &b)
		if n*a != m*b {
			Fprintln(out, "NO")
			return
		}

		edges := make([][]edge, n+m+2)
		addEdge := func(from, to int, cap int) {
			edges[from] = append(edges[from], edge{to, len(edges[to]), cap})
			edges[to] = append(edges[to], edge{from, len(edges[from]) - 1, 0})
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				addEdge(i, n+j, 1)
			}
		}
		st, end := n+m, n+m+1
		for i := 0; i < n; i++ {
			addEdge(st, i, a)
		}
		for i := 0; i < m; i++ {
			addEdge(n+i, end, b)
		}

		level := make([]int, n+m+2)
		calcLevel := func() bool {
			for i := range level {
				level[i] = -1
			}
			level[st] = 0
			q := []int{st}
			for len(q) > 0 {
				v := q[0]
				q = q[1:]
				for _, e := range edges[v] {
					if w := e.to; e.cap > 0 && level[w] < 0 {
						level[w] = level[v] + 1
						q = append(q, w)
					}
				}
			}
			return level[end] >= 0
		}
		var iter []int
		var dfs func(int, int) int
		dfs = func(v int, mf int) int {
			if v == end {
				return mf
			}
			for i := iter[v]; i < len(edges[v]); i++ {
				e := &edges[v][i]
				if w := e.to; e.cap > 0 && level[w] > level[v] {
					if f := dfs(w, min(mf, e.cap)); f > 0 {
						e.cap -= f
						edges[w][e.rev].cap += f
						return f
					}
				}
				iter[v]++
			}
			return 0
		}
		const inf int = 1e9
		for calcLevel() {
			iter = make([]int, n+m+2)
			for {
				if f := dfs(st, inf); f > 0 {
					maxFlow += f
				} else {
					break
				}
			}
		}
		if maxFlow < n*a {
			Fprintln(out, "NO")
			return
		}
		Fprintln(out, "YES")
		for i := 0; i < n; i++ {
			ans := make([]byte, m)
			for j, e := range edges[i][:m] {
				ans[j] = '1' - byte(e.cap)
			}
			Fprintln(out, string(ans))
		}
	}

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

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

package main

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

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

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

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

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

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

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		line := readNNums(reader, 4)
		n, m, a, b := line[0], line[1], line[2], line[3]
		ok, g := solve(n, m, a, b)
		if ok {
			fmt.Println("YES")
			for i := 0; i < n; i++ {
				fmt.Println(string(g[i]))
			}
		} else {
			fmt.Println("NO")
		}
	}
}

func solve(n, m, a, b int) (bool, [][]byte) {
	if n*a != b*m {
		return false, nil
	}

	G := make([][]byte, n)
	cnt := make([]int, m)

	for i := 0; i < n; i++ {
		G[i] = make([]byte, m)
		var x int
		// put a ones in this column
		for j := 0; j < m; j++ {
			if cnt[j] < b && x < a {
				G[i][j] = '1'
				cnt[j]++
				x++
			} else {
				G[i][j] = '0'
			}
		}
	}

	return true, G
}

/*
URL:
https://codeforces.com/contest/1360/problem/G
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, m int
	a, b int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m, a, b = ReadInt4()
		solve(n, m, a, b)
	}
}

func solve(n, m, a, b int) {
	if a == 0 && b == 0 {
		sub(n, m, a, b)
		return
	}

	if n*a != m*b {
		fmt.Println("NO")
		return
	}
	if !(n%b == 0 && m%a == 0) {
		fmt.Println("NO")
		return
	}

	res := [][]rune{}

	C := make([]int, m)

	for i := 0; i < n; i++ {
		row := []rune{}

		nokori := a
		for j := 0; j < m; j++ {
			if C[j] < b && nokori > 0 {
				row = append(row, '1')
				C[j]++
				nokori--
			} else {
				row = append(row, '0')
			}
		}

		res = append(res, row)
	}

	for i := 0; i < n; i++ {
		tmp := 0
		for j := 0; j < m; j++ {
			if res[i][j] == '1' {
				tmp++
			}
		}
		if tmp != a {
			fmt.Println("NO")
			return
		}
	}
	for j := 0; j < m; j++ {
		tmp := 0
		for i := 0; i < n; i++ {
			if res[i][j] == '1' {
				tmp++
			}
		}
		if tmp != b {
			fmt.Println("NO")
			return
		}
	}

	// sum := 0
	// for i := 0; i < n; i++ {
	// 	for j := 0; j < m; j++ {
	// 		if res[i][j] == '1' {
	// 			sum++
	// 		}
	// 	}
	// }
	// if sum != n*a || sum != m*b {
	// 	fmt.Println("NO")
	// 	return
	// }

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		fmt.Println(string(res[i]))
	}
}

func sub(n, m, a, b int) {
	res := [][]rune{}
	for i := 0; i < n; i++ {
		row := []rune{}
		for j := 0; j < m; j++ {
			row = append(row, '0')
		}
		res = append(res, row)
	}

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		fmt.Println(string(res[i]))
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

/*
URL:
https://codeforces.com/contest/1360/problem/G
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, m int
	a, b int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m, a, b = ReadInt4()
		solve(n, m, a, b)
	}
}

func solve(n, m, a, b int) {
	if n*a != m*b {
		fmt.Println("NO")
		return
	}

	res := [][]rune{}

	C := make([]int, m)

	for i := 0; i < n; i++ {
		row := []rune{}

		nokori := a
		for j := 0; j < m; j++ {
			if C[j] < b && nokori > 0 {
				row = append(row, '1')
				C[j]++
				nokori--
			} else {
				row = append(row, '0')
			}
		}

		res = append(res, row)
	}

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		fmt.Println(string(res[i]))
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

/*
URL:
https://codeforces.com/contest/1360/problem/G
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, m int
	a, b int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m, a, b = ReadInt4()
		solve(n, m, a, b)
	}
}

func solve(n, m, a, b int) {
	// if a == 0 && b == 0 {
	// 	sub(n, m, a, b)
	// 	return
	// }

	// if n*a != m*b {
	// 	fmt.Println("NO")
	// 	return
	// }
	// if !(n%b == 0 && m%a == 0) {
	// 	fmt.Println("NO")
	// 	return
	// }

	res := [][]rune{}

	C := make([]int, m)

	for i := 0; i < n; i++ {
		row := []rune{}

		nokori := a
		for j := 0; j < m; j++ {
			if C[j] < b && nokori > 0 {
				row = append(row, '1')
				C[j]++
				nokori--
			} else {
				row = append(row, '0')
			}
		}

		res = append(res, row)
	}

	for i := 0; i < n; i++ {
		tmp := 0
		for j := 0; j < m; j++ {
			if res[i][j] == '1' {
				tmp++
			}
		}
		if tmp != a {
			fmt.Println("NO")
			return
		}
	}
	for j := 0; j < m; j++ {
		tmp := 0
		for i := 0; i < n; i++ {
			if res[i][j] == '1' {
				tmp++
			}
		}
		if tmp != b {
			fmt.Println("NO")
			return
		}
	}

	// sum := 0
	// for i := 0; i < n; i++ {
	// 	for j := 0; j < m; j++ {
	// 		if res[i][j] == '1' {
	// 			sum++
	// 		}
	// 	}
	// }
	// if sum != n*a || sum != m*b {
	// 	fmt.Println("NO")
	// 	return
	// }

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		fmt.Println(string(res[i]))
	}
}

func sub(n, m, a, b int) {
	res := [][]rune{}
	for i := 0; i < n; i++ {
		row := []rune{}
		for j := 0; j < m; j++ {
			row = append(row, '0')
		}
		res = append(res, row)
	}

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		fmt.Println(string(res[i]))
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

/*
URL:
https://codeforces.com/contest/1360/problem/G
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, m int
	a, b int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m, a, b = ReadInt4()
		solve(n, m, a, b)
	}
}

func solve(n, m, a, b int) {
	if n*a != m*b {
		fmt.Println("NO")
		return
	}

	res := [][]rune{}

	C := make([]int, m)

	for i := 0; i < n; i++ {
		row := []rune{}

		nokori := a
		for j := 0; j < m; j++ {
			if C[j] < b && nokori > 0 {
				row = append(row, '1')
				C[j]++
				nokori--
			} else {
				row = append(row, '0')
			}
		}

		res = append(res, row)
	}

	sum := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if res[i][j] == '1' {
				sum++
			}
		}
	}
	if sum != n*a || sum != m*b {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		fmt.Println(string(res[i]))
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

/*
URL:
https://codeforces.com/contest/1360/problem/G
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, m int
	a, b int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m, a, b = ReadInt4()
		solve(n, m, a, b)
	}
}

func solve(n, m, a, b int) {
	if n*a != m*b {
		fmt.Println("NO")
		return
	}
	if !(n%b == 0 && m%a == 0) {
		fmt.Println("NO")
		return
	}

	res := [][]rune{}

	C := make([]int, m)

	for i := 0; i < n; i++ {
		row := []rune{}

		nokori := a
		for j := 0; j < m; j++ {
			if C[j] < b && nokori > 0 {
				row = append(row, '1')
				C[j]++
				nokori--
			} else {
				row = append(row, '0')
			}
		}

		res = append(res, row)
	}

	// sum := 0
	// for i := 0; i < n; i++ {
	// 	for j := 0; j < m; j++ {
	// 		if res[i][j] == '1' {
	// 			sum++
	// 		}
	// 	}
	// }
	// if sum != n*a || sum != m*b {
	// 	fmt.Println("NO")
	// 	return
	// }

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		fmt.Println(string(res[i]))
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

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

	var t, n, m, a, b int
o:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b)
		if n%b != 0 || m%a != 0 {
			Fprintln(out, "NO")
			continue
		}
		ans := make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, m)
			for j := range ans[i] {
				ans[i][j] = '0'
			}
		}
		for i := 0; i < n; i++ {
			st := i / b * a
			for j := st; j < st+a; j++ {
				if j >= m {
					Fprintln(out, "NO")
					continue o
				}
				ans[i][j] = '1'
			}
		}
		Fprintln(out, "YES")
		for _, an := range ans {
			Fprintln(out, string(an))
		}
	}
}

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

package main

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

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

	var t, n, m, a, b int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b)
		if n%b != 0 || m%a != 0 || n*a != m*b {
			Fprintln(out, "NO")
			continue
		}
		ans := make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, m)
			for j := range ans[i] {
				ans[i][j] = '0'
			}
		}
		for i := 0; i < n; i++ {
			st := i / b * a
			for j := st; j < st+a; j++ {
				ans[i][j] = '1'
			}
		}
		Fprintln(out, "YES")
		for _, an := range ans {
			Fprintln(out, string(an))
		}
	}
}

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

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)

	for tt := rd(); tt > 0; tt-- {
		n, m, a, b := rd(), rd(), rd(), rd()
		if n*a != b*m {
			Fprintln(out, "NO")
			continue
		}
		ans := make([][]int, n)
		c := 0
		for i := 0; i < n; i++ {
			ans[i] = make([]int, m)
			ans[i][c] = 1
			c = (c + 1) % m
		}
		Fprintln(out, "YES")
		for _, i := range ans {
			for _, j := range i {
				Fprint(out, j)
			}
			Fprintln(out)
		}
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}