package main

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

/*
4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
*/

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

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var idxSlice []int
		for i := 0; i < len(result); i++ {
			idxSlice = append(idxSlice, i)
		}

		var find bool
		for i := 0; i < len(idxSlice); i++ {
			var resultSlices [][]int

			next := make([]int, len(idxSlice)-1)
			var src []int
			switch {
			case i == 0:
				src = idxSlice[i+1:]
			case i == len(idxSlice)-1:
				src = idxSlice[:i]
			default:
				src = append(idxSlice[:i], idxSlice[i+1:]...)
			}
			copy(next, src)
			if !dfsd(result, &next, &resultSlices, i) {
				continue
			} else {
				Fprintln(out, "YES")
				for _, data := range resultSlices {
					Fprintln(out, data[0], data[1])
				}
				find = true
				break
			}
		}

		if !find {
			Fprintln(out, "NO")
		}

	}
}

func dfsd(result []int64, idxslice *[]int, road *[][]int, pre int) bool {
	if len(*idxslice) == 0 {
		return true
	}

	tmp := make([]int, len(*idxslice))
	copy(tmp, *idxslice)
	for i := 0; i < len(tmp); i++ {
		if result[(*idxslice)[i]] != result[pre] {
			*road = append(*road, []int{pre + 1, (*idxslice)[i] + 1})
			pre_next := (*idxslice)[i]
			Println(*idxslice, pre, tmp, road)
			switch {
			case i == 0:
				*idxslice = (*idxslice)[i+1:]
			case i == len(*idxslice)-1:
				*idxslice = (*idxslice)[:i]
			default:
				*idxslice = append((*idxslice)[:i], (*idxslice)[i+1:]...)
			}

			if dfsd(result, idxslice, road, pre_next) {
				return true
			} else {
				idxslice = &tmp
			}
		}
	}
	return false
}

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

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

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var road [][]int
		duplicate := make(map[int]struct{})
		duplicate[0] = struct{}{}
		stack := []int{0}
		find := false

		for len(stack) != 0 {
			cur := stack[0]
			stack = stack[1:]
			for idx := 0; idx < len(result); idx++ {
				if _, ok := duplicate[idx]; !ok {
					if cur != idx && result[cur] != result[idx] {
						road = append(road, []int{cur, idx})
						stack = append(stack, idx)
						duplicate[idx] = struct{}{}
					}
				}
			}

			if len(duplicate) == len(result) {
				Fprintln(out, "YES")
				for _, data := range road {
					Fprintln(out, data[0]+1, data[1]+1)
				}
				find = true
				break
			}
		}

		if !find {
			Fprintln(out, "NO")
		}

	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		solve(n, a)
	}
}

func solve(n int, a []int) {
	m := make(map[int][]int)
	maxSize := 0
	for i, ai := range a {
		m[ai] = append(m[ai], i+1)
		maxSize = Max(maxSize, len(m[ai]))
	}
	if maxSize == n {
		println("NO")
		return
	}

	println("YES")

	second := 0
	tmp := make([]int, 0)
	for i := 1; i < n; i++ {
		if a[i] == a[0] {
			tmp = append(tmp, i+1)
		} else {
			println(1, i+1)
			second = i + 1
		}
	}
	for i := 0; i < len(tmp); i++ {
		println(second, tmp[i])
	}
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func solve() {
	t := readInt()
	for j := 0; j < t; j++ {
		n := readInt()
		a := readIntArray(n)
		solveSingle(a)
	}
}

func solveSingle(a []int) {
	n := len(a)
	connected := make(map[int]map[int]bool)
	for i := 0; i < n; i++ {
		connected[i] = make(map[int]bool)
	}
	for i := 0; i < n; i++ {
		if len(connected[i]) > 0 {
			continue
		}
		for j := 0; j < n; j++ {
			if a[i] != a[j] && !connected[i][j] {
				connected[i][j] = true
				connected[j][i] = true
				break
			}
		}
	}
	u := n - 1
	if len(connected[u]) == 0 {
		for j := 0; j < n - 1; j++ {
			if a[u] != a[j] && !connected[u][j] {
				connected[u][j] = true
				connected[j][u] = true
				break
			}
		}
	}
	vis := make(map[int]bool, n)
	dfs(connected, 0, vis)
	if len(vis) == n {
		fmt.Println("YES")
		for v := 0; v < n; v++ {
			for u := range connected[v] {
				if v < u {
					fmt.Println(v+1, u+1)
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

func dfs(connected map[int]map[int]bool, from int, vis map[int]bool) {
	vis[from] = true
	for next := range connected[from] {
		if !vis[next] {
			dfs(connected, next, vis)
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		pos := map[int][]int{}
		for i := range a {
			Fscan(in, &a[i])
			pos[a[i]] = append(pos[a[i]], i)
		}
		if len(pos) == 1 {
			Fprintln(out, "NO")
			return
		}
		Fprintln(out, "YES")
		next := 0
		for v, ps := range pos {
			if v == a[0] {
				continue
			}
			next = v
			for _, p := range ps {
				Fprintln(out, pos[a[0]][0]+1, p+1)
			}
		}
		for _, p := range pos[a[0]][1:] {
			Fprintln(out, pos[next][0]+1, p+1)
		}
	}

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

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

package main

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

type Gangster struct {
	Gang, City int
}

type Pair struct {
	First, Second int
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

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

		arr := make([]Gangster, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i].Gang)
			arr[i].City = i + 1
		}

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

		ans := make([]Pair, 0)
		var last int

		for i := (n - 1); i >= 0; i-- {
			if arr[i].Gang == arr[0].Gang {
				last = i
				break
			}

			var p Pair
			p.First = arr[0].City
			p.Second = arr[i].City

			ans = append(ans, p)
		}

		if len(ans) == 0 {
			fmt.Println("NO")
			continue
		}

		for i := last; i > 0; i-- {
			var p Pair
			p.First = arr[i].City
			p.Second = arr[n-1].City
			ans = append(ans, p)
		}

		fmt.Println("YES")
		l := len(ans)
		for i := 0; i < l; i++ {
			fmt.Printf("%d %d\n", ans[i].First, ans[i].Second)
		}
	}
}

package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) bool {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
		return false
	}
	if len(roadConnections) > numberDistricts[testCase]-1 {
		fmt.Println("NO")
		return false
	}
	fmt.Println("YES")
	printRoadConnections(roadConnections)
	return true
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	var err error
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]

	zip := Zipper{districts, makeRange(1, districtCount)}
	districtMap := zip.Sort()
	// fmt.Println(districtMap)
	roadConnections = connectFirstDistrict(roadConnections, districtMap, districtCount)
	// fmt.Println(roadConnections)
	roadConnections, err = connectRemainingDistricts(roadConnections, districtMap, districtCount)
	// fmt.Println(roadConnections)

	return roadConnections, err
}

func connectFirstDistrict(roadConnections [][]int, districtMap [][]int, count int) [][]int {
	for i := 1; i < count; i++ {
		if districtMap[i][0] != districtMap[0][0] {
			roadConnections = append(roadConnections, []int{districtMap[0][1], districtMap[i][1]})
		}
	}
	return roadConnections
}

func connectRemainingDistricts(roadConnections [][]int, districtMap [][]int, count int) ([][]int, error) {
	var err error
	for i := 1; i < count; i++ {
		if districtMap[0][0] != districtMap[i][0] {
			return roadConnections, err
		}
		connection, err := findNextViableConnection(districtMap, count, i)
		roadConnections = append(roadConnections, connection)
		if err != nil {
			return roadConnections, err
		}
	}
	return roadConnections, err
}

func findNextViableConnection(districtMap [][]int, count int, index int) ([]int, error) {
	var err error
	for j := index + 1; j < count; j++ {
		if districtMap[index][0] != districtMap[j][0] {
			return []int{districtMap[index][1], districtMap[j][1]}, err
		}
	}
	return []int{districtMap[index][1], districtMap[index][1]}, errors.New("Districts not connectable")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}

//Zipper contains two slices where the elements are tied together
type Zipper struct {
	A, B []int
}

//Zip creates a slice with zipped elements of A and B
func (zip Zipper) Zip() [][]int {
	var zipped [][]int
	if len(zip.A) != len(zip.B) {
		panic("Can only zip slices with equal dimensions")
	}
	for i := 0; i < len(zip.A); i++ {
		zipped = append(zipped, []int{zip.A[i], zip.B[i]})
	}
	return zipped
}

//Sort A or B while keeping the elements tied together
func (zip Zipper) Sort() [][]int {
	zipped := zip.Zip()
	sort.Slice(zipped, func(i, j int) bool {
		return zipped[i][0] < zipped[j][0]
	})
	return zipped
}

package main

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

var T, n int

var _r = bufio.NewReader(os.Stdin)
var _w = bufio.NewWriter(os.Stdout)

func main() {
	for _, _ = fmt.Fscan(_r, &T); T > 0; T-- {
		_, _ = fmt.Fscan(_r, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			_, _ = fmt.Fscan(_r, &a[i])
		}

		pos := -1
		for i := 2; i <= n; i++ {
			if a[i] != a[1] {
				pos = i
				break
			}
		}
		if pos == -1 {
			_, _ = fmt.Fprintln(_w, "NO")
			_ = _w.Flush()
			continue
		}

		_, _ = fmt.Fprintln(_w, "YES")
		for i := 2; i <= n; i++ {
			if a[i] == a[1] {
				_, _ = fmt.Fprintln(_w, i, pos)
			} else {
				_, _ = fmt.Fprintln(_w, 1, i)
			}
		}
		_ = _w.Flush()
	}
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		solve(n, a)
	}
}

func solve(n int, a []int) {
	m := make(map[int][]int)
	maxSize := 0
	for i, ai := range a {
		m[ai] = append(m[ai], i+1)
		maxSize = Max(maxSize, len(m[ai]))
	}

	if maxSize*2-1 > n {
		println("NO")
		return
	}
	println("YES")

	type Gang struct {
		Districts []int
	}

	gangs := make([]*Gang, 0)
	for _, districts := range m {
		gangs = append(gangs, &Gang{districts})
	}
	sort.Slice(gangs, func(i, j int) bool {
		return len(gangs[i].Districts) > len(gangs[j].Districts)
	})

	ans := make([]int, 0)
	for len(ans) < n {
		for _, gang := range gangs {
			if len(gang.Districts) > 0 {
				ans = append(ans, gang.Districts[0])
				gang.Districts = gang.Districts[1:]
			}
		}
	}

	for i := 0; i < n-1; i++ {
		println(ans[i], ans[i+1])
	}
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		solve(n, a)
	}
}

func solve(n int, a []int) {
	m := make(map[int][]int)
	maxSize := 0
	for i, ai := range a {
		m[ai] = append(m[ai], i+1)
		maxSize = Max(maxSize, len(m[ai]))
	}
	if maxSize == n {
		println("NO")
		return
	}

	println("YES")

	tmp := make([]int, 0)
	for i := 1; i < n; i++ {
		if a[i] == a[0] {
			tmp = append(tmp, i+1)
		} else {
			println(1, i+1)
		}
	}
	for i := 0; i < len(tmp); i++ {
		println(2, tmp[i])
	}
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		solve(n, a)
	}
}

func solve(n int, a []int) {
	m := make(map[int][]int)
	maxSize := 0
	for i, ai := range a {
		m[ai] = append(m[ai], i+1)
		maxSize = Max(maxSize, len(m[ai]))
	}

	if maxSize*2-1 > n {
		println("NO")
		return
	}
	println("YES")

	type Gang struct {
		Districts []int
	}

	gangs := make([]*Gang, 0)
	for _, districts := range m {
		gangs = append(gangs, &Gang{districts})
	}
	sort.Slice(gangs, func(i, j int) bool {
		return len(gangs[i].Districts) > len(gangs[j].Districts)
	})

	ans := make([]int, 0)
	for len(ans) < n {
		c := 0
		for i := 0; i < len(gangs); i++ {
			gang := gangs[i]
			if len(gang.Districts) > 0 {
				c++
				ans = append(ans, gang.Districts[0])
				gang.Districts = gang.Districts[1:]
			}
			if c == 2 {
				break
			}
		}
	}

	for i := 0; i < n-1; i++ {
		println(ans[i], ans[i+1])
	}
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func print(a ...interface{})            { fmt.Fprint(_w, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

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

func solve() {
	t := readInt()
	for j := 0; j < t; j++ {
		n := readInt()
		a := readIntArray(n)
		solveSingle(a)
	}
}

func solveSingle(a []int) {
	n := len(a)
	connected := make(map[int]map[int]bool)
	for i := 0; i < n; i++ {
		connected[i] = make(map[int]bool)
	}
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if a[i] != a[j] && !connected[i][j] {
				connected[i][j] = true
				connected[j][i] = true
			}
		}
	}
	vis := make(map[int]bool, n)
	dfs(connected, 0, vis)
	if len(vis) == n {
		fmt.Println("YES")
		for v := 0; v < n; v++ {
			for u := range connected[v] {
				if v < u {
					fmt.Println(v + 1, u + 1)
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

func dfs(connected map[int]map[int]bool, from int, vis map[int]bool) {
	vis[from] = true
	for next := range connected[from] {
		if !vis[next] {
			dfs(connected, next, vis)
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

func solve() {
	t := readInt()
	for j := 0; j < t; j++ {
		n := readInt()
		a := readIntArray(n)
		solveSingle(a)
	}
}

func solveSingle(a []int) {
	n := len(a)
	connected := make(map[int]map[int]bool)
	for i := 0; i < n; i++ {
		connected[i] = make(map[int]bool)
	}
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if a[i] != a[j] && !connected[i][j] {
				connected[i][j] = true
				connected[j][i] = true
				break
			}
		}
	}
	u := n - 1
	for j := 0; j < n; j++ {
		if a[u] != a[j] && !connected[u][j] {
			connected[u][j] = true
			connected[j][u] = true
			break
		}
	}
	vis := make(map[int]bool, n)
	dfs(connected, 0, vis)
	if len(vis) == n {
		fmt.Println("YES")
		for v := 0; v < n; v++ {
			for u := range connected[v] {
				if v < u {
					fmt.Println(v+1, u+1)
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

func dfs(connected map[int]map[int]bool, from int, vis map[int]bool) {
	vis[from] = true
	for next := range connected[from] {
		if !vis[next] {
			dfs(connected, next, vis)
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

func solve() {
	t := readInt()
	for j := 0; j < t; j++ {
		n := readInt()
		a := readIntArray(n)
		solveSingle(a)
	}
}

func solveSingle(a []int) {
	n := len(a)
	connected := make(map[int]map[int]bool)
	for i := 0; i < n; i++ {
		connected[i] = make(map[int]bool)
	}
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if a[i] != a[j] && !connected[i][j] {
				connected[i][j] = true
				connected[j][i] = true
				break
			}
		}
	}
	vis := make(map[int]bool, n)
	dfs(connected, 0, vis)
	if len(vis) == n {
		fmt.Println("YES")
		for v := 0; v < n; v++ {
			for u := range connected[v] {
				if v < u {
					fmt.Println(v + 1, u + 1)
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

func dfs(connected map[int]map[int]bool, from int, vis map[int]bool) {
	vis[from] = true
	for next := range connected[from] {
		if !vis[next] {
			dfs(connected, next, vis)
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

func solve() {
	t := readInt()
	for j := 0; j < t; j++ {
		n := readInt()
		a := readIntArray(n)
		solveSingle(a)
	}
}

func solveSingle(a []int) {
	n := len(a)
	connected := make(map[int]map[int]bool)
	for i := 0; i < n; i++ {
		connected[i] = make(map[int]bool)
	}
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if a[i] != a[j] && !connected[i][j] {
				connected[i][j] = true
				connected[j][i] = true
				break
			}
		}
	}
	if len(connected[n - 1]) == 0 {
		u := n - 1
		for j := 0; j < n; j++ {
			if a[u] != a[j] && !connected[u][j] {
				connected[u][j] = true
				connected[j][u] = true
				break
			}
		}
	}
	vis := make(map[int]bool, n)
	dfs(connected, 0, vis)
	if len(vis) == n {
		fmt.Println("YES")
		for v := 0; v < n; v++ {
			for u := range connected[v] {
				if v < u {
					fmt.Println(v+1, u+1)
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

func dfs(connected map[int]map[int]bool, from int, vis map[int]bool) {
	vis[from] = true
	for next := range connected[from] {
		if !vis[next] {
			dfs(connected, next, vis)
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

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

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

package main

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

type Gangster struct {
	Gang, City int
}

type Pair struct {
	First, Second int
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

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

		arr := make([]Gangster, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i].Gang)
			arr[i].City = i + 1
		}

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

		ans := make([]Pair, 0)
		var last int

		for i := (n - 1); i >= 0; i-- {
			if arr[i].Gang == arr[0].Gang {
				last = i - 1
				break
			}

			var p Pair
			p.First = arr[0].City
			p.Second = arr[i].City

			ans = append(ans, p)
		}

		if len(ans) == 0 {
			fmt.Println("NO")
			continue
		}

		for i := last; i >= 0; i-- {
			var p Pair
			p.First = arr[i].City
			p.Second = arr[n-1].City
			ans = append(ans, p)
		}

		fmt.Println("YES")
		l := len(ans)
		for i := 0; i < l; i++ {
			fmt.Printf("%d %d\n", ans[i].First, ans[i].Second)
		}
	}
}

package main

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

type Gangster struct {
	Gang, City int
}

type Pair struct {
	First, Second int
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

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

		arr := make([]Gangster, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i].Gang)
			arr[i].City = i + 1
		}

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

		ans := make([]Pair, 0)
		var last int

		for i := (n - 1); i >= 0; i-- {
			if arr[i].Gang == arr[0].Gang {
				last = i - 1
				break
			}

			var p Pair
			p.First = arr[0].City
			p.Second = arr[i].City

			ans = append(ans, p)
		}

		if len(ans) == 0 || last < 0 {
			fmt.Println("NO")
			continue
		}

		for i := last; i >= 0; i-- {
			var p Pair
			p.First = arr[i].City
			p.Second = arr[n-1].City
			ans = append(ans, p)
		}

		fmt.Println("YES")
		l := len(ans)
		for i := 0; i < l; i++ {
			fmt.Printf("%d %d\n", ans[i].First, ans[i].Second)
		}
	}
}

package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
	printRoadConnections(roadConnections)
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]
	_, indexMap, err := sortDistricts(districts, districtCount)
	if err != nil {
		return roadConnections, err
	}
	for i := 0; i < len(indexMap)-1; i++ {
		slice := []int{indexMap[i], indexMap[i+1]}
		roadConnections = append(roadConnections, slice)
	}
	return roadConnections, err

}

//sortDistricts tries to sort districts in a way that there are no more
//successive equal values
func sortDistricts(districts []int, districtCount int) ([]int, []int, error) {
	var err error
	indexMap := makeRange(1, districtCount)
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			districts, indexMap, err = shiftDistrict(districts, indexMap, i+1)
		}
	}
	return districts, indexMap, err
}

//shiftDistrict checks for the first best position in the slice (no neighbors
// with equal value) and shifts that value to said position (also adjusts
// indexMap in a similar fashion)
func shiftDistrict(districts []int, indexMap []int, districtIndex int) ([]int, []int, error) {
	var err error
	for j := 0; j < len(districts); j++ {
		mainCon := (j != districtIndex)
		con1 := (districts[j] != districts[districtIndex])
		edgeCon := (j == 0 || j == len(districts)-1)

		if edgeCon && mainCon && con1 {
			districts, _ = shiftSliceElement(districts, districtIndex, j)
			indexMap, _ = shiftSliceElement(indexMap, districtIndex, j)
			return districts, indexMap, err
		}

		if !edgeCon {
			if mainCon && con1 && districts[j+1] != districts[districtIndex] {
				districts, _ = shiftSliceElement(districts, districtIndex, j)
				indexMap, _ = shiftSliceElement(indexMap, districtIndex, j)
				return districts, indexMap, err
			}
		}
	}
	return districts, indexMap, errors.New("Can't sort districts")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func shiftSliceElement(slice []int, targetIndex int, destinationIndex int) ([]int, error) {
	var newSlice []int
	if targetIndex > len(slice) || destinationIndex > len(slice) {
		return slice, errors.New("can't work with 42")
	}
	if targetIndex < destinationIndex {
		newSlice = append(newSlice, slice[:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:destinationIndex+1]...)
		newSlice = append(newSlice, slice[targetIndex])
		if destinationIndex < len(slice)-1 {
			newSlice = append(newSlice, slice[destinationIndex+1:]...)
		}
	}
	if targetIndex > destinationIndex {
		newSlice = append(newSlice, slice[:destinationIndex]...)
		newSlice = append(newSlice, slice[targetIndex])
		newSlice = append(newSlice, slice[destinationIndex:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:]...)
	}

	return newSlice, nil
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}

package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
	printRoadConnections(roadConnections)
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]
	sortedDistricts, indexMap, err := sortDistricts(districts, districtCount)
	if err != nil {
		return roadConnections, err
	}
	if !sanityCheck(sortedDistricts) {
		return roadConnections, errors.New("Can't sort districts")
	}
	for i := 0; i < len(indexMap)-1; i++ {
		slice := []int{indexMap[i], indexMap[i+1]}
		roadConnections = append(roadConnections, slice)
	}
	return roadConnections, err

}

//sortDistricts tries to sort districts in a way that there are no more
//successive equal values
func sortDistricts(districts []int, districtCount int) ([]int, []int, error) {
	var err error
	indexMap := makeRange(1, districtCount)
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			districts, indexMap, err = shiftDistrict(districts, indexMap, i+1)
		}
	}
	return districts, indexMap, err
}

//shiftDistrict checks for the first best position in the slice (no neighbors
// with equal value) and shifts that value to said position (also adjusts
// indexMap in a similar fashion)
func shiftDistrict(districts []int, indexMap []int, districtIndex int) ([]int, []int, error) {
	var err error
	for j := 0; j < len(districts); j++ {
		mainCon := (j != districtIndex)
		con1 := (districts[j] != districts[districtIndex])
		edgeCon := (j == 0 || j == len(districts)-1)

		if edgeCon && mainCon && con1 {
			districts, _ = shiftSliceElement(districts, districtIndex, j)
			indexMap, _ = shiftSliceElement(indexMap, districtIndex, j)
			return districts, indexMap, err
		}

		if !edgeCon {
			if mainCon && con1 && districts[j+1] != districts[districtIndex] {
				districts, _ = shiftSliceElement(districts, districtIndex, j)
				indexMap, _ = shiftSliceElement(indexMap, districtIndex, j)
				return districts, indexMap, err
			}
		}
	}
	return districts, indexMap, errors.New("Can't sort districts")
}

func sanityCheck(districts []int) bool {
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			return false
		}
	}
	return true
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func shiftSliceElement(slice []int, targetIndex int, destinationIndex int) ([]int, error) {
	var newSlice []int
	if targetIndex > len(slice) || destinationIndex > len(slice) {
		return slice, errors.New("can't work with 42")
	}
	if targetIndex < destinationIndex {
		newSlice = append(newSlice, slice[:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:destinationIndex+1]...)
		newSlice = append(newSlice, slice[targetIndex])
		if destinationIndex < len(slice)-1 {
			newSlice = append(newSlice, slice[destinationIndex+1:]...)
		}
	}
	if targetIndex > destinationIndex {
		newSlice = append(newSlice, slice[:destinationIndex]...)
		newSlice = append(newSlice, slice[targetIndex])
		newSlice = append(newSlice, slice[destinationIndex:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:]...)
	}

	return newSlice, nil
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}

package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) bool {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
		return false
	}
	if len(roadConnections) > numberDistricts[testCase]-1 {
		fmt.Println("NO")
		return false
	}
	fmt.Println("YES")
	printRoadConnections(roadConnections)
	return true
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	var err error
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]

	zip := Zipper{districts, makeRange(1, districtCount)}
	districtMap := zip.Sort()
	// fmt.Println(districtMap)
	roadConnections = connectFirstDistrict(roadConnections, districtMap, districtCount)
	// fmt.Println(roadConnections)
	roadConnections, err = connectRemainingDistricts(roadConnections, districtMap, districtCount)
	// fmt.Println(roadConnections)

	return roadConnections, err
}

func connectFirstDistrict(roadConnections [][]int, districtMap [][]int, count int) [][]int {
	for i := 1; i < count; i++ {
		if districtMap[i][0] != districtMap[0][0] {
			roadConnections = append(roadConnections, []int{districtMap[0][1], districtMap[i][1]})
		}
	}
	return roadConnections
}

func connectRemainingDistricts(roadConnections [][]int, districtMap [][]int, count int) ([][]int, error) {
	var err error
	for i := 2; i < count; i++ {
		if districtMap[0][0] != districtMap[i][0] {
			return roadConnections, err
		}
		connection, err := findNextViableConnection(districtMap, count, i)
		roadConnections = append(roadConnections, connection)
		if err != nil {
			return roadConnections, err
		}
	}
	return roadConnections, err
}

func findNextViableConnection(districtMap [][]int, count int, index int) ([]int, error) {
	var err error
	for j := index + 1; j < count; j++ {
		if districtMap[index][0] != districtMap[j][0] {
			return []int{districtMap[index][1], districtMap[j][1]}, err
		}
	}
	return []int{districtMap[index][1], districtMap[index][1]}, errors.New("Districts not connectable")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}

//Zipper contains two slices where the elements are tied together
type Zipper struct {
	A, B []int
}

//Zip creates a slice with zipped elements of A and B
func (zip Zipper) Zip() [][]int {
	var zipped [][]int
	if len(zip.A) != len(zip.B) {
		panic("Can only zip slices with equal dimensions")
	}
	for i := 0; i < len(zip.A); i++ {
		zipped = append(zipped, []int{zip.A[i], zip.B[i]})
	}
	return zipped
}

//Sort A or B while keeping the elements tied together
func (zip Zipper) Sort() [][]int {
	zipped := zip.Zip()
	sort.Slice(zipped, func(i, j int) bool {
		return zipped[i][0] < zipped[j][0]
	})
	return zipped
}

package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
	printRoadConnections(roadConnections)
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]
	_, indexMap, err := sortDistricts(districts, districtCount)
	if err != nil {
		return roadConnections, err
	}
	for i := 0; i < len(indexMap)-1; i++ {
		slice := []int{indexMap[i], indexMap[i+1]}
		roadConnections = append(roadConnections, slice)
	}
	return roadConnections, err

}

//sortDistricts tries to sort districts in a way that there are no more
//successive equal values
func sortDistricts(districts []int, districtCount int) ([]int, []int, error) {
	var err error
	indexMap := makeRange(1, districtCount)
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			districts, indexMap, err = shiftDistrict(districts, indexMap, i+1)
		}
	}
	fmt.Println(districts)
	return districts, indexMap, err
}

//shiftDistrict checks for the next different value from districts[districtIndex]
//and shifts this element to that index and also return adjusted indexMap
func shiftDistrict(districts []int, indexMap []int, districtIndex int) ([]int, []int, error) {
	var err error
	for j := districtIndex + 1; j < len(districts); j++ {
		if districts[j] != districts[districtIndex] {
			districts, _ = shiftSliceElement(districts, j, districtIndex)
			indexMap, _ = shiftSliceElement(indexMap, j, districtIndex)
			return districts, indexMap, err
		}
	}
	if districts[len(districts)-1] == districts[len(districts)-2] {
		if districts[len(districts)-1] != districts[0] {
			districts, _ = shiftSliceElement(districts, len(districts)-1, 0)
			indexMap, _ = shiftSliceElement(indexMap, len(districts)-1, 0)
			return districts, indexMap, err
		}
		for j := 0; j < len(districts)-1; j++ {
			con1 := districts[j] != districts[len(districts)-1]
			con2 := districts[j+1] != districts[len(districts)-1]
			notEqualCon := districts[j] != districts[len(districts)-1]
			if con1 && con2 && notEqualCon {
				districts, _ = shiftSliceElement(districts, districts[len(districts)-1], j)
				indexMap, _ = shiftSliceElement(indexMap, indexMap[len(districts)-1], j)
				return districts, indexMap, err
			}
		}
	}
	return districts, indexMap, errors.New("Can't sort districts")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func shiftSliceElement(slice []int, targetIndex int, destinationIndex int) ([]int, error) {
	var newSlice []int
	if targetIndex > len(slice) || destinationIndex > len(slice) {
		return slice, errors.New("can't work with 42")
	}
	if targetIndex < destinationIndex {
		newSlice = append(newSlice, slice[:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:destinationIndex+1]...)
		newSlice = append(newSlice, slice[targetIndex])
		if destinationIndex < len(slice)-1 {
			newSlice = append(newSlice, slice[destinationIndex+1:]...)
		}
	}
	if targetIndex > destinationIndex {
		newSlice = append(newSlice, slice[:destinationIndex]...)
		newSlice = append(newSlice, slice[targetIndex])
		newSlice = append(newSlice, slice[destinationIndex:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:]...)
	}

	return newSlice, nil
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}

package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 10*4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) bool {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
		return false
	}
	if len(roadConnections) > numberDistricts[testCase]-1 {
		fmt.Println("NO")
		return false
	}
	fmt.Println("YES")
	printRoadConnections(roadConnections)
	return true
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	var err error
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]

	zip := Zipper{districts, makeRange(1, districtCount)}
	districtMap := zip.Sort()

	roadConnections = connectFirstDistrict(roadConnections, districtMap, districtCount)
	roadConnections, err = connectRemainingDistricts(roadConnections, districtMap, districtCount)

	return roadConnections, err
}

func connectFirstDistrict(roadConnections [][]int, districtMap [][]int, count int) [][]int {
	for i := 1; i < count; i++ {
		if districtMap[i][0] != districtMap[0][0] {
			roadConnections = append(roadConnections, []int{1, districtMap[i][1]})
		}
	}
	return roadConnections
}

func connectRemainingDistricts(roadConnections [][]int, districtMap [][]int, count int) ([][]int, error) {
	var err error
	for i := 1; i < count; i++ {
		if districtMap[0][0] != districtMap[i][0] {
			return roadConnections, err
		}
		connection, err := findNextViableConnection(districtMap, count, i)
		roadConnections = append(roadConnections, connection)
		if err != nil {
			return roadConnections, err
		}
	}
	return roadConnections, err
}

func findNextViableConnection(districtMap [][]int, count int, index int) ([]int, error) {
	var err error
	for j := index + 1; j < count; j++ {
		if districtMap[index][0] != districtMap[j][0] {
			return []int{districtMap[index][1], districtMap[j][1]}, err
		}
	}
	return []int{districtMap[index][1], districtMap[index][1]}, errors.New("Districts not connectable")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}

//Zipper contains two slices where the elements are tied together
type Zipper struct {
	A, B []int
}

//Zip creates a slice with zipped elements of A and B
func (zip Zipper) Zip() [][]int {
	var zipped [][]int
	if len(zip.A) != len(zip.B) {
		panic("Can only zip slices with equal dimensions")
	}
	for i := 0; i < len(zip.A); i++ {
		zipped = append(zipped, []int{zip.A[i], zip.B[i]})
	}
	return zipped
}

//Sort A or B while keeping the elements tied together
func (zip Zipper) Sort() [][]int {
	zipped := zip.Zip()
	sort.Slice(zipped, func(i, j int) bool {
		return zipped[i][0] < zipped[j][0]
	})
	return zipped
}

package main

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

var (
	numberDistricts  []int
	districtsByGangs [][]int
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	bf := make([]byte, 4096)
	scanner.Buffer(bf, 4096*4096)

	testCases := convertInputToInt(stdInput(scanner, 1))[0]
	collectTestCases(scanner, testCases)
	for index := range numberDistricts {
		processTestCase(index)
	}

}

func collectTestCases(scanner *bufio.Scanner, testCases int) {
	for i := 0; i < testCases; i++ {
		districts := convertInputToInt(stdInput(scanner, 1))[0]
		numberDistricts = append(numberDistricts, districts)
		districtsByGangs = append(districtsByGangs, convertInputToInt(stdInput(scanner, districts)))
	}
}

func processTestCase(testCase int) {
	roadConnections, err := findRoadConnections(testCase)
	if err != nil {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
	printRoadConnections(roadConnections)
}

func printRoadConnections(roadConnections [][]int) {
	for _, slice := range roadConnections {
		fmt.Println(slice[0], slice[1])
	}
}

func findRoadConnections(testCase int) ([][]int, error) {
	var roadConnections [][]int
	districts := districtsByGangs[testCase]
	districtCount := numberDistricts[testCase]
	_, indexMap, err := sortDistricts(districts, districtCount)
	if err != nil {
		return roadConnections, err
	}
	for i := 0; i < len(indexMap)-1; i++ {
		slice := []int{indexMap[i], indexMap[i+1]}
		roadConnections = append(roadConnections, slice)
	}
	return roadConnections, err

}

//sortDistricts tries to sort districts in a way that there are no more
//successive equal values
func sortDistricts(districts []int, districtCount int) ([]int, []int, error) {
	var err error
	indexMap := makeRange(1, districtCount)
	for i := 0; i < len(districts)-1; i++ {
		if districts[i] == districts[i+1] {
			districts, indexMap, err = shiftDistrict(districts, indexMap, i+1)
		}
	}
	return districts, indexMap, err
}

//shiftDistrict checks for the next different value from districts[districtIndex]
//and shifts this element to that index and also return adjusted indexMap
func shiftDistrict(districts []int, indexMap []int, districtIndex int) ([]int, []int, error) {
	var err error
	for j := districtIndex + 1; j < len(districts); j++ {
		if districts[j] != districts[districtIndex] {
			districts, _ = shiftSliceElement(districts, j, districtIndex)
			indexMap, _ = shiftSliceElement(indexMap, j, districtIndex)
			return districts, indexMap, err
		}
	}
	return districts, indexMap, errors.New("Can't sort districts")
}

///////// UTILS ///////////

func stdInput(scanner *bufio.Scanner, varCount int) []string {
	var inputParameters []string

	scanner.Scan()
	input := strings.Split(scanner.Text(), " ")
	for i := 0; i < varCount; i++ {
		inputParameters = append(inputParameters, input[i])
	}
	return inputParameters
}

func convertInputToInt(variables []string) []int {
	var convertedInput []int
	for _, value := range variables {
		convertedVar, _ := strconv.Atoi(value)
		convertedInput = append(convertedInput, convertedVar)
	}
	return convertedInput
}

func shiftSliceElement(slice []int, targetIndex int, destinationIndex int) ([]int, error) {
	var newSlice []int
	if targetIndex > len(slice) || destinationIndex > len(slice) {
		return slice, errors.New("can't work with 42")
	}
	if targetIndex < destinationIndex {
		newSlice = append(newSlice, slice[:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:destinationIndex+1]...)
		newSlice = append(newSlice, slice[targetIndex])
		if destinationIndex < len(slice)-1 {
			newSlice = append(newSlice, slice[destinationIndex+1:]...)
		}
	}
	if targetIndex > destinationIndex {
		newSlice = append(newSlice, slice[:destinationIndex]...)
		newSlice = append(newSlice, slice[targetIndex])
		newSlice = append(newSlice, slice[destinationIndex:targetIndex]...)
		newSlice = append(newSlice, slice[targetIndex+1:]...)
	}

	return newSlice, nil
}

func makeRange(start int, stop int) []int {
	if start < stop {
		slice := make([]int, stop-start+1)
		for i := 0; i < stop; i++ {
			slice[i] = start + i
		}
		return slice
	}
	if stop < start {
		slice := make([]int, start-stop+1)
		for i := 0; i < len(slice); i++ {
			slice[i] = start - i
		}
		return slice
	}
	return []int{start}
}

package main

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

/*
4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
*/

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

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var idxSlice []int
		for i := 0; i < len(result); i++ {
			idxSlice = append(idxSlice, i)
		}

		var find bool
		for i := 0; i < len(idxSlice); i++ {
			var resultSlices [][]int

			next := make([]int, len(idxSlice)-1)
			var src []int
			switch {
			case i == 0:
				src = idxSlice[i+1:]
			case i == len(idxSlice)-1:
				src = idxSlice[:i]
			default:
				src = append(idxSlice[:i], idxSlice[i+1:]...)
			}
			copy(next, src)
			if !dfsd(result, &next, &resultSlices, i) {
				continue
			} else {
				Fprintln(out, "YES")
				for _, data := range resultSlices {
					Fprintln(out, data[0], data[1])
				}
				find = true
				break
			}
		}

		if !find {
			Fprintln(out, "NO")
		}

	}
}

func dfsd(result []int64, idxslice *[]int, road *[][]int, pre int) bool {
	if len(*idxslice) == 0 {
		return true
	}

	tmp := make([]int, len(*idxslice))
	copy(tmp, *idxslice)
	for i := 0; i < len(tmp); i++ {
		if result[(*idxslice)[i]] != result[pre] {
			*road = append(*road, []int{pre + 1, (*idxslice)[i] + 1})
			pre_next := (*idxslice)[i]
			Println(*idxslice, pre, tmp, road)
			switch {
			case i == 0:
				*idxslice = (*idxslice)[i+1:]
			case i == len(*idxslice)-1:
				*idxslice = (*idxslice)[:i]
			default:
				*idxslice = append((*idxslice)[:i], (*idxslice)[i+1:]...)
			}

			if dfsd(result, idxslice, road, pre_next) {
				return true
			} else {
				idxslice = &tmp
			}
		}
	}
	return false
}

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

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

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var road [][]int
		duplicate := make(map[int]struct{})
		duplicate[0] = struct{}{}
		stack := []int{0}
		find := false

		for len(stack) != 0 {
			cur := stack[0]
			stack = stack[1:]
			for idx := 0; idx < len(result); idx++ {
				if _, ok := duplicate[idx]; !ok {
					if cur != idx && result[cur] != result[idx] {
						road = append(road, []int{cur, idx})
						stack = append(stack, idx)
						duplicate[idx] = struct{}{}
					}
				}
			}

			if len(duplicate) == len(result) {
				Fprintln(out, "YES")
				for _, data := range road {
					Fprintln(out, data[0], data[1])
				}
				find = true
				break
			}
		}

		if !find {
			Fprintln(out, "NO")
		}

	}
}

package main

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

/*
4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
*/

func dfs_connection(result []int64, idxslice []int, road *[][]int, pre int) bool {
	if len(idxslice) == 0 {
		return true
	}

	for i := 0; i < len(idxslice); i++ {
		if result[idxslice[i]] != result[pre] {
			*road = append(*road, []int{pre+1, idxslice[i]+1})
			pre = idxslice[i]
			next := make([]int, len(idxslice)-1)
			var src []int
			switch {
			case i == 0:
				src = idxslice[i+1:]
			case i == len(idxslice)-1:
				src = idxslice[:i]
			default:
				src = append(idxslice[:i], idxslice[i+1:]...)
			}
			copy(next, src)

			return dfs_connection(result, next, road, pre)
		}
	}
	return false
}

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

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var idxSlice []int

		for i := 0; i < len(result); i++ {
			idxSlice = append(idxSlice, i)
		}

		var resultSlices [][]int
		if !dfs_connection(result, idxSlice[1:], &resultSlices, 0) {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
			for _, data := range resultSlices {
				Fprintln(out, data[0],data[1])
			}
		}
	}
}

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

package main

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

/*
4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
*/

func dfs_connection(result []int64, idxslice []int, road *[][]int, pre int) bool {
	if len(idxslice) == 0 {
		return true
	}

	for i := 0; i < len(idxslice); i++ {
		if result[idxslice[i]] != result[pre] {
			*road = append(*road, []int{pre, idxslice[i]})
			pre = idxslice[i]
			next := make([]int, len(idxslice)-1)
			var src []int
			switch {
			case i == 0:
				src = idxslice[i+1:]
			case i == len(idxslice)-1:
				src = idxslice[:i]
			default:
				src = append(idxslice[:i], idxslice[i+1:]...)
			}
			copy(next, src)

			return dfs_connection(result, next, road, pre)
		}
	}
	return false
}

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

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var idxSlice []int

		for i := 0; i < len(result); i++ {
			idxSlice = append(idxSlice, i)
		}

		var resultSlices [][]int
		if !dfs_connection(result, idxSlice[1:], &resultSlices, 0) {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
			for _, data := range resultSlices {
				Fprintln(out, data)
			}
		}
	}
}

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

package main

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

/*
4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
*/

func dfs_connection(result []int64, idxslice []int, road [][]int, results *[][]int, pre_end, pre_start int) bool {
	if len(idxslice) == 0 {
		for _, data := range road {
			*results = append(*results, data)
		}
		return true
	}

	for i := 0; i < len(idxslice); i++ {
		if result[idxslice[i]] != result[pre_end] {
			tmp := append(road, []int{pre_end + 1, idxslice[i] + 1})
			pre_end = idxslice[i]
			next := make([]int, len(idxslice)-1)
			var src []int
			switch {
			case i == 0:
				src = idxslice[i+1:]
			case i == len(idxslice)-1:
				src = idxslice[:i]
			default:
				src = append(idxslice[:i], idxslice[i+1:]...)
			}
			copy(next, src)

			if dfs_connection(result, next, tmp, results, pre_end, pre_start) {
				return true
			}
		}

		if result[idxslice[i]] != result[pre_start] {
			tmp := append(road, []int{pre_start + 1, idxslice[i] + 1})
			pre_end = idxslice[i]
			next := make([]int, len(idxslice)-1)
			var src []int
			switch {
			case i == 0:
				src = idxslice[i+1:]
			case i == len(idxslice)-1:
				src = idxslice[:i]
			default:
				src = append(idxslice[:i], idxslice[i+1:]...)
			}
			copy(next, src)

			if dfs_connection(result, next, tmp, results, pre_end, pre_start) {
				return true
			}
		}
	}
	return false
}

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

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var idxSlice []int

		for i := 0; i < len(result); i++ {
			idxSlice = append(idxSlice, i)
		}

		var resultSlices, tmp [][]int
		if !dfs_connection(result, idxSlice[1:], tmp, &resultSlices, 0, 0) {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
			for _, data := range resultSlices {
				Fprintln(out, data[0], data[1])
			}
		}
	}
}

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

package main

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

/*
4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
*/

func dfs_connection(result []int64, idxslice []int, road [][]int, results *[][]int, pre_end, pre_start int) bool {
	if len(idxslice) == 0 {
		for _, data := range road {
			*results = append(*results, data)
		}
		return true
	}

	for i := 0; i < len(idxslice); i++ {
		if result[idxslice[i]] != result[pre_end] {
			tmp := append(road, []int{pre_end + 1, idxslice[i] + 1})
			pre_end = idxslice[i]
			next := make([]int, len(idxslice)-1)
			var src []int
			switch {
			case i == 0:
				src = idxslice[i+1:]
			case i == len(idxslice)-1:
				src = idxslice[:i]
			default:
				src = append(idxslice[:i], idxslice[i+1:]...)
			}
			copy(next, src)

			if dfs_connection(result, next, tmp, results, pre_end, pre_start) {
				return true
			}
		}

		if result[idxslice[i]] != result[pre_start] {
			tmp := append(road, []int{pre_start + 1, idxslice[i] + 1})
			pre_end = idxslice[i]
			next := make([]int, len(idxslice)-1)
			var src []int
			switch {
			case i == 0:
				src = idxslice[i+1:]
			case i == len(idxslice)-1:
				src = idxslice[:i]
			default:
				src = append(idxslice[:i], idxslice[i+1:]...)
			}
			copy(next, src)

			if dfs_connection(result, next, tmp, results, pre_end, pre_start) {
				return true
			}
		}
	}
	return false
}

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

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var idxSlice []int

		for i := 0; i < len(result); i++ {
			idxSlice = append(idxSlice, i)
		}

		var find bool
		var resultSlices, tmp [][]int
		for i := 0; i < len(result); i++ {
			next := make([]int, len(idxSlice)-1)
			var src []int
			switch {
			case i == 0:
				src = idxSlice[i+1:]
			case i == len(idxSlice)-1:
				src = idxSlice[:i]
			default:
				src = append(idxSlice[:i], idxSlice[i+1:]...)
			}
			copy(next, src)
			if !dfs_connection(result, next, tmp, &resultSlices, i, i) {
				continue
			} else {
				Fprintln(out, "YES")
				for _, data := range resultSlices {
					Fprintln(out, data[0], data[1])
				}
				find = true
				break
			}
		}

		if !find {
			Fprintln(out, "NO")
		}

	}
}

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

package main

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

/*
4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
*/

func dfs_connection(result []int64, idxslice []int, road *[][]int, pre int) bool {
	if len(idxslice) == 0 {
		return true
	}

	for i := 0; i < len(idxslice); i++ {
		if result[idxslice[i]] != result[pre] {
			*road = append(*road, []int{pre+1, idxslice[i]+1})
			pre = idxslice[i]
			next := make([]int, len(idxslice)-1)
			var src []int
			switch {
			case i == 0:
				src = idxslice[i+1:]
			case i == len(idxslice)-1:
				src = idxslice[:i]
			default:
				src = append(idxslice[:i], idxslice[i+1:]...)
			}
			copy(next, src)

			return dfs_connection(result, next, road, pre)
		}
	}
	return false
}

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

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var result []int64
		for Fscan(in, &N); N > 0; N-- {
			Fscan(in, &S)
			result = append(result, S)
		}

		var idxSlice []int

		for i := 0; i < len(result); i++ {
			idxSlice = append(idxSlice, i)
		}

		var resultSlices [][]int
		if !dfs_connection(result, idxSlice[1:], &resultSlices, 0) {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
			for _, data := range resultSlices {
				Fprintln(out, data)
			}
		}
	}
}

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


package main

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

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

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

		var n, k int
		fmt.Fscan(r, &n, &k)
		res := "NO"

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

		fmt.Fprintln(w, res)
	}

}

package main

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

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

func solve() {
    var n, k int
    Fscan(in, &n, &k)
    ok := false
    for i := 0; i < n; i++ {
        var x int;
        Fscan(in, &x)
        if x == 1 {
            ok = true
        }
    }

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

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

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

func solve() {
    var n, k int
    Fscan(in, &n, &k)
    ok := false
    for i := 0; i < n; i++ {
        var x int;
        Fscan(in, &x)
        if x == 1 {
            ok = true
        }
    }

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

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

    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }

    out.Flush()
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
    var n, k int
    Fscan(in, &n, &k)
    ok := false
    for i := 0; i < n; i++ {
        var x int;
        Fscan(in, &x)
        if x == 1 {
            ok = true
        }
    }

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

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

    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve(in, out)
    }

    out.Flush()
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
    var n, k int
    Fscan(in, &n, &k)
    ok := false
    for i := 0; i < n; i++ {
        var x int;
        Fscan(in, &x)
        if x == 1 {
            ok = true
        }
    }

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

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

    // Println(reflect.TypeOf(in))
    // Println(reflect.TypeOf(out))

    // solve := func() {
    //     var n, k int
    //     Fscan(in, &n, &k)
    //     ok := false
    //     for i := 0; i < n; i++ {
    //         var x int;
    //         Fscan(in, &x)
    //         if x == 1 {
    //             ok = true
    //         }
    //     }

    //     if ok {
    //         Fprintln(out, "YES");
    //     } else {
    //         Fprintln(out, "NO");
    //     }
    // }

    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve(in, out)
    }
}

package main

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

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

    solve := func() {
        var n, k int
        Fscan(in, &n, &k)
        ok := false
        for i := 0; i < n; i++ {
            var x int;
            Fscan(in, &x)
            if x == 1 {
                ok = true
            }
        }

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

    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
}

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() {
        var n, k int
        Fscan(in, &n, &k)
        ok := false
        for i := 0; i < n; i++ {
            var x int;
            Fscan(in, &x)
            if x == 1 {
                ok = true
            }
        }

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

    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
}

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

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

package main

import (
    ."fmt"
    ."os"
)

func solve() {

    var n, k int
    Fscan(Stdin, &n, &k)
    var ok bool
   	for i := 0; i < n; i++ {
   		var x int;
   		Fscan(Stdin, &x)
   		if x == 1 {
   			ok = true
   		}
   	}

   	if ok {
   		Fprintln(Stdout, "YES");
   	} else {
   		Fprintln(Stdout, "NO");
   	}
}

func main() {
	var T int;
	Fscan(Stdin, &T)
	for ; T > 0; T-- {
		solve()
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.Replace(text, "\r\n", "", -1)
	t := 0
	t, _ = strconv.Atoi(text)
	for i := 0; i < t; i++ {
		raw, _ := reader.ReadString('\n')
		raw = strings.Replace(raw, "\r\n", "", -1)
		n, _ := strconv.Atoi(strings.Split(raw, " ")[0])
		k, _ := strconv.Atoi(strings.Split(raw, " ")[1])
		raw, _ = reader.ReadString('\n')
		raw = strings.Replace(raw, "\r\n", "", -1)
		split := strings.Split(raw, " ")
		arr := make([]int, n)
		for ic, ch := range split {
			arr[ic], _ = strconv.Atoi(ch)
		}
		//  kx-x+y=n-1
		if !contains(arr, 1) {
			fmt.Println("NO")
		} else {
			fmt.Println(search(n, k))
		}
	}
}

func search(n int, k int) string {
	for x := 0; x < 100; x++ {
		for y := 0; y < 100; y++ {
			s := k*x - x + y + 1
			if s == n {
				return "YES"
			}
		}
	}
	return "NO"
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func change(arr []int, a1 int, a2 int) {
	min := min(arr)
	arr = append(arr[0:a1], min)
	arr = append(arr, arr[a2:len(arr)]...)
}

func min(arr []int) int {
	min := math.MaxInt
	for _, i := range arr {
		if i < min {
			min = i
		}
	}
	return min
}

package main

import (
	"fmt"
)

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

		var numArr []int
		var n int
		var k int
		fmt.Scan(&n)
		fmt.Scan(&k)
		for i := 0; i < n; i++ {

			var num3 int
			fmt.Scan(&num3)
			numArr = append(numArr, num3)
		}
		var res string
		res = max(numArr)
		fmt.Println(res)
		// var res string
		// res = sec(numArr)
	}

}

func max(arr []int) string {
	for i := 0; i < len(arr); i++ {
		if arr[i] == 1 {
			return "YES"
		}
	}
	return "NO"
}

package main

import (
	."fmt"
	."os"
)

func solve() {
	var n, k int
	Fscan(Stdin, &n, &k)
	var ok bool
	for i := 0; i < n; i++ {
		var x int
		Fscan(Stdin, &x)
		if x == 1 {
			ok = true
		}
	}
	if ok {
		Fprintln(Stdout, "YES")
	} else {
		Fprintln(Stdout, "NO")
	}
}

func main() {
	var t int
	Fscan(Stdin, &t)
	for ; t>0; t-- {
		solve()
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

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

func pl(a ...interface{}) { fmt.Println(a...) }
func pf(format string, a ...interface{}) { fmt.Printf(format, a...) }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }

func main() {
	var T int
	scan(&T)

	for ; T > 0; T-- {
    var n, k int
    scan(&n, &k)
    var can bool
    for i:=0 ; i < n; i++ {
      var x int
      scan(&x)
      if x == 1 {
        can = true
      }
    }
    pf("%s\n", ys(can))
	}
}

func ys(b bool) string { return map[bool]string {true: "YES", false: "NO"}[b] }

package main

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

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

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

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

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

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

/**
Run solve the problem CF1746A
Date: 10/16/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1746/A
Problem: CF1746A
**/
func (in *CF1746A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, _ := in.NextInt(), in.NextInt()
		ans := false
		for i := 0; i < n; i++ {
			val := in.NextInt()
			if val == 1 {
				ans = true
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

package main

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

func main() {
	var tc int

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

	defer writer.Flush()

	fmt.Fscan(reader, &tc)

	for t := 0; t < tc; t++ {
		var n, k int

		fmt.Fscan(reader, &n, &k)

		arr := make([]int, n)

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

		output := solve(&arr, n)

		fmt.Fprintln(writer, output)
	}
}

func solve(arr *[]int, n int) string {
	ans := "NO"
	for i := 0; i < n; i++ {

		if (*arr)[i] == 1 {
			ans = "YES"
			break
		}
	}
	return ans
}

package main

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

func main() {
	var tc int

	r_ := bufio.NewReader(os.Stdin)
	w_ := bufio.NewWriter(os.Stdout)

	defer w_.Flush()

	fmt.Fscan(r_, &tc)

	for t := 0; t < tc; t++ {
		var n, k int

		fmt.Fscan(r_, &n, &k)

		aa := make([]int, n)
		t := false
		for i := 0; i < n; i++ {
			var tt int
			fmt.Fscan(r_, &tt)
			aa[i] = tt
		}
		for i := 0; i < n; i++ {

			if aa[i] == 1 {
				t = true
				break
			}
		}

		o := "NO"
		if t == true {
			o = "YES"
		}
		fmt.Fprintln(w_, o)
	}
}

package main

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

const cf = true

func solve() {
	var n, k int
	fmt.Fscan(in, &n, &k)
	arr := make([]int, n)
	hasOne := false
	for i := range arr {
		fmt.Fscan(in, &arr[i])
		if arr[i] == 1 {
			hasOne = true
		}
	}
	if !hasOne {
		fmt.Fprintln(out, "NO")
		return
	}
	fmt.Fprintln(out, "YES")
}

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

func GCD(a, b int) int {
	for a != b {
		if a > b {
			a -= b
		} else {
			b -= a
		}
	}

	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 main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

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

		var f bool
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v == 1 {
				f = true
			}
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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 _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	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 _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		n, k := _int(), _int()
		a := make([]int, n)
		for i := range a {
			a[i] = _int()
		}
		printf("%s\n", sol(n, k, a))
	}
}

func sol(n, k int, a []int) string {
	for _, i := range a {
		if i == 1 {
			return "YES"
		}
	}
	return "NO"
}

package main

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

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

    var n, k int
    Fscan(in, &n, &k)
    ok := false
    for i := 0; i < n; i++ {
        var x int;
        Fscan(in, &x)
        if x == 1 {
            ok = true
        }
    }

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

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

    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve(os.Stdin, os.Stdout)
    }
}

package main

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

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

	var n, k int
    Fscan(in, &n, &k)
    var ok bool
   	for i := 0; i < n; i++ {
   		var x int;
   		Fscan(in, &x)
   		if x == 1 {
   			ok = true
   		}
   	}

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

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

	var T int
	Fscan(in, &T)
	for ; T > 0; T-- {
		solve(os.Stdin, os.Stdout)
	}
}

package main

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

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

    var n, k int
    Fscan(in, &n, &k)
    var ok bool
   	for i := 0; i < n; i++ {
   		var x int;
   		Fscan(in, &x)
   		if x == 1 {
   			ok = true
   		}
   	}

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

func main() {
	var T int;
	in := bufio.NewReader(os.Stdin)
	Fscan(in, &T)
	for ; T > 0; T-- {
		solve()
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.Replace(text, "\r\n", "", -1)
	t := 0
	t, _ = strconv.Atoi(text)
	for i := 0; i < t; i++ {
		raw, _ := reader.ReadString('\n')
		raw = strings.Replace(raw, "\r\n", "", -1)
		n, _ := strconv.Atoi(strings.Split(raw, " ")[0])
		k, _ := strconv.Atoi(strings.Split(raw, " ")[1])
		raw, _ = reader.ReadString('\n')
		raw = strings.Replace(raw, "\r\n", "", -1)
		split := strings.Split(raw, " ")
		arr := make([]int, n)
		for ic, ch := range split {
			arr[ic], _ = strconv.Atoi(ch)
		}
		//  kx-x+y=n-1
		if !contains(arr, 1) {
			println("NO")
		} else {
			println(search(n, k))
		}
	}
}

func search(n int, k int) string {
	for x := 0; x < 100; x++ {
		for y := 0; y < 100; y++ {
			s := k*x - x + y + 1
			if s == n {
				return "YES"
			}
		}
	}
	return "NO"
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func change(arr []int, a1 int, a2 int) {
	min := min(arr)
	arr = append(arr[0:a1], min)
	arr = append(arr, arr[a2:len(arr)]...)
}

func min(arr []int) int {
	min := math.MaxInt
	for _, i := range arr {
		if i < min {
			min = i
		}
	}
	return min
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.Replace(text, "\r\n", "", -1)
	t := 0
	t, _ = strconv.Atoi(text)
	for i := 0; i < t; i++ {
		raw, _ := reader.ReadString('\n')
		raw = strings.Replace(raw, "\r\n", "", -1)
		n, _ := strconv.Atoi(strings.Split(raw, " ")[0])
		k, _ := strconv.Atoi(strings.Split(raw, " ")[1])
		raw, _ = reader.ReadString('\n')
		raw = strings.Replace(raw, "\r\n", "", -1)
		split := strings.Split(raw, " ")
		arr := make([]int, n)
		for ic, ch := range split {
			arr[ic], _ = strconv.Atoi(ch)
		}
		//  kx-x+y=n-1
		if !contains(arr, 1) {
			println("NO")
			break
		}
		println(search(n, k))
	}
}

func search(n int, k int) string {
	for x := 0; x < 100; x++ {
		for y := 0; y < 100; y++ {
			s := k*x - x + y + 1
			if s == n {
				return "YES"
			}
		}
	}
	return "NO"
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func change(arr []int, a1 int, a2 int) {
	min := min(arr)
	arr = append(arr[0:a1], min)
	arr = append(arr, arr[a2:len(arr)]...)
}

func min(arr []int) int {
	min := math.MaxInt
	for _, i := range arr {
		if i < min {
			min = i
		}
	}
	return min
}

package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Println(runtime.NumCPU())

	var num int
	fmt.Scan(&num)
	for i := 0; i < num; i++ {

		var numArr []int
		var n int
		var k int
		fmt.Scan(&n)
		fmt.Scan(&k)
		for i := 0; i < n; i++ {

			var num3 int
			fmt.Scan(&num3)
			numArr = append(numArr, num3)
		}
		var res string
		res = max(numArr)
		fmt.Println(res)
		// var res string
		// res = sec(numArr)
	}

}

func max(arr []int) string {
	for i := 0; i < len(arr); i++ {
		if arr[i] == 1 {
			return "YES"
		}
	}
	return "NO"
}

package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Println(runtime.NumCPU())

	var num int
	fmt.Scan(&num)
	for i := 0; i < num; i++ {

		var numArr []int
		var n int
		var k int
		fmt.Scan(&n)
		fmt.Scan(&k)
		for i := 0; i < n; i++ {

			var num3 int
			fmt.Scan(&num3)
			numArr = append(numArr, num3)
		}
		var res string
		res = max(numArr)
		fmt.Println(res)
		// var res string
		// res = sec(numArr)
	}

}

func max(arr []int) string {
	for i := 0; i < len(arr); i++ {
		if arr[i] == 1 {
			return "yes"
		}
	}
	return "no"
}


package main

import (
	"fmt"
)

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

	var total, max int

	for i := 0; i < count; i++ {
		var l int
		fmt.Scan(&l)
		total += l
		if l > max {
			max = l
		}
	}

	fmt.Println(max - (total - max) + 1)
}

package main

import "fmt"

func main() {
    var count, max, sum, number, i int64
    fmt.Scan(&count)
    for i=0; i<count; i++ {
        fmt.Scan(&number)
        if max<number {
            sum+=max
            max=number
        } else {
            sum+=number
        }
    }
    number=max-sum
    if number<0 {
        number=0
    } else {
        number++
    }
    fmt.Println(number)
}

package main

import (
	"fmt"
)

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

	var total, max int

	for i := 0; i < count; i++ {
		var l int
		fmt.Scan(&l)
		total += l
		if l > max {
			max = l
		}
	}
	fmt.Println(total - max + 1)
}