package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextLong() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextDouble() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

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

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

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

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

func main() {
	io := NewIo()
	defer io.Flush()
	N := io.NextInt()
	K := io.NextInt()
	A := make([]int, 4)
	for i := 0; i < 4; i++ {
		A[i] = io.NextInt()
	}
	if N == 4 || K < N - 1 + 2 {
		io.PrintLn(-1)
	} else {
		used := make([]bool, N + 1)
		for i := 0; i < 4; i++ {
			used[A[i]] = true
		}
		B := []int{}
		for i := 1; i <= N; i++ {
			if !used[i] {
				B = append(B, i)
			}
		}
		X := []int{}
		X = append(X, A[0])
		X = append(X, A[2])
		for i := 0; i < len(B); i++ {
			X = append(X, B[i])
		}
		X = append(X, A[3])
		X = append(X, A[1])

		Y := []int{}
		Y = append(Y, A[2])
		Y = append(Y, A[0])
		for i := 0; i < len(B); i++ {
			Y = append(Y, B[i])
		}
		Y = append(Y, A[1])
		Y = append(Y, A[3])
		io.PrintIntLn(X)
		io.PrintIntLn(Y)
	}
}

package main

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

func main() {
	defer out.Flush()
	n := in.NextInt()
	k := in.NextInt()
	a := in.NextInt()
	b := in.NextInt()
	c := in.NextInt()
	d := in.NextInt()
	if n == 4 {
		fmt.Fprintln(out, -1)
		return
	}
	if k < n+1 {
		fmt.Fprintln(out, -1)
		return
	}
	x := make([]int, n)
	x[0] = a
	x[1] = c
	x[n-2] = d
	x[n-1] = b
	for i, j := 2, 0; i < n-2; i++ {
		for {
			j++
			if j != a && j != b && j != c && j != d {
				break
			}
		}
		x[i] = j
	}
	for i := 0; i < n; i++ {
		if i != 0 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, x[i])
	}
	fmt.Fprintln(out)
	x[0], x[1] = x[1], x[0]
	x[n-1], x[n-2] = x[n-2], x[n-1]
	for i := 0; i < n; i++ {
		if i != 0 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, x[i])
	}
	fmt.Fprintln(out)
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	var err error
	for len(r.buf) == 0 && err != io.EOF {
		buf := new(bytes.Buffer)
		for {
			var chunk []byte
			var more bool
			chunk, more, err = r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}

package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextLong() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextDouble() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

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

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

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

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

func main() {
	io := NewIo()
	defer io.Flush()
	N := io.NextInt()
	K := io.NextInt()
	A := make([]int, 4)
	for i := 0; i < 4; i++ {
		A[i] = io.NextInt()
	}
	if (N == 4 && K == 4) || K < N - 4 - 1 + 6 {
		io.PrintLn(-1)
	} else {
		used := make([]bool, N + 1)
		for i := 0; i < 4; i++ {
			used[A[i]] = true
		}
		B := []int{}
		for i := 1; i <= N; i++ {
			if !used[i] {
				B = append(B, i)
			}
		}
		X := []int{}
		X = append(X, A[0])
		X = append(X, A[2])
		for i := 0; i < len(B); i++ {
			X = append(X, B[i])
		}
		X = append(X, A[3])
		X = append(X, A[1])

		Y := []int{}
		Y = append(Y, A[2])
		Y = append(Y, A[0])
		for i := 0; i < len(B); i++ {
			Y = append(Y, B[i])
		}
		Y = append(Y, A[1])
		Y = append(Y, A[3])
		io.PrintIntLn(X)
		io.PrintIntLn(Y)
	}
}

package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextLong() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextDouble() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

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

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

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

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

func main() {
	io := NewIo()
	defer io.Flush()
	N := io.NextInt()
	K := io.NextInt()
	A := make([]int, 4)
	for i := 0; i < 4; i++ {
		A[i] = io.NextInt()
	}
	if K < N - 4 - 1 + 6 {
		io.PrintLn(-1)
	} else {
		used := make([]bool, N + 1)
		for i := 0; i < 4; i++ {
			used[A[i]] = true
		}
		B := []int{}
		for i := 1; i <= N; i++ {
			if !used[i] {
				B = append(B, i)
			}
		}
		X := []int{}
		X = append(X, A[0])
		X = append(X, A[2])
		for i := 0; i < len(B); i++ {
			X = append(X, B[i])
		}
		X = append(X, A[3])
		X = append(X, A[1])

		Y := []int{}
		Y = append(Y, A[2])
		Y = append(Y, A[0])
		for i := 0; i < len(B); i++ {
			Y = append(Y, B[i])
		}
		Y = append(Y, A[1])
		Y = append(Y, A[3])
		io.PrintIntLn(X)
		io.PrintIntLn(Y)
	}
}

package main

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

func main() {
	defer out.Flush()
	n := in.NextInt()
	k := in.NextInt()
	a := in.NextInt()
	b := in.NextInt()
	c := in.NextInt()
	d := in.NextInt()
	if n == 4 {
		if k < 4 {
			fmt.Fprintln(out, -1)
			return
		}
		fmt.Fprintln(out, a, c, d, b)
		fmt.Fprintln(out, c, a, b, d)
		return
	}
	if k < n+1 {
		fmt.Fprintln(out, -1)
		return
	}
	x := make([]int, n)
	x[0] = a
	x[1] = c
	x[n-2] = d
	x[n-1] = b
	for i, j := 2, 0; i < n-2; i++ {
		for {
			j++
			if j != a && j != b && j != c && j != d {
				break
			}
		}
		x[i] = j
	}
	for i := 0; i < n; i++ {
		if i != 0 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, x[i])
	}
	fmt.Fprintln(out)
	x[0], x[1] = x[1], x[0]
	x[n-1], x[n-2] = x[n-2], x[n-1]
	for i := 0; i < n; i++ {
		if i != 0 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, x[i])
	}
	fmt.Fprintln(out)
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	var err error
	for len(r.buf) == 0 && err != io.EOF {
		buf := new(bytes.Buffer)
		for {
			var chunk []byte
			var more bool
			chunk, more, err = r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}

package main

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

func main() {
	defer out.Flush()
	n := in.NextInt()
	k := in.NextInt()
	a := in.NextInt()
	b := in.NextInt()
	c := in.NextInt()
	d := in.NextInt()
	if k < n {
		fmt.Fprintln(out, -1)
		return
	}
	x := make([]int, n)
	x[0] = a
	x[1] = c
	x[2] = d
	x[n-1] = b
	for i, j := 3, 0; i < n-1; i++ {
		for {
			j++
			if j != a && j != b && j != c && j != d {
				break
			}
		}
		x[i] = j
	}
	for i := 0; i < n; i++ {
		if i != 0 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, x[i])
	}
	fmt.Fprintln(out)
	fmt.Fprint(out, c, " ", a, " ", b)
	for i := n - 2; i >= 3; i-- {
		fmt.Fprint(out, " ", x[i])
	}
	fmt.Fprint(out, " ", d)
	fmt.Fprintln(out)
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	var err error
	for len(r.buf) == 0 && err != io.EOF {
		buf := new(bytes.Buffer)
		for {
			var chunk []byte
			var more bool
			chunk, more, err = r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}


package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			os.Stdin.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 := map[[2]int64]int{}
	e := func(x, y int64) int {
		a, b := x, y
		for a > 0 {
			a, b = b%a, a
		}
		p := [2]int64{x / b, y / b}
		if _, ok := id[p]; !ok {
			id[p] = len(id)
		}
		return id[p]
	}
	n := r()
	type nb struct{ w, i int }
	g := make([][]nb, 2*n)
	for i := 1; i <= n; i++ {
		a,b,c,d := int64(r()), int64(r()), int64(r()), int64(r())
		v, w := e(b*c, (a+b)*d), e(b*(c+d), a*d)
		g[v] = append(g[v], nb{w, i})
		g[w] = append(g[w], nb{v, i})
	}

	ds := make([][]int, len(id))
	vis := make([]int, len(id))
	var f func(int, int)
	f = func(v, p int) {
		vis[v] = 1
		for _, e := range g[v] {
			w, i := e.w, e.i
			if i == p || vis[w] == 2 {
				continue
			}
			if vis[w] > 0 {
				ds[v] = append(ds[v], i)
			} else {
				f(w, i)
				if len(ds[w])&1 > 0 {
					ds[w] = append(ds[w], i)
				} else {
					ds[v] = append(ds[v], i)
				}
			}
		}
		vis[v] = 2
	}
	for i, b := range vis {
		if b == 0 {
			f(i, 0)
		}
	}

	s:=0
	for _, d := range ds {
		s += len(d) / 2
	}
	Fprintln(out, s)
	for _, d := range ds {
		for i := 0; i+1 < len(d); i += 2 {
			Fprintln(out, d[i], d[i+1])
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			os.Stdin.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 := map[[2]int64]int{}
	genID := func(x, y int64) int {
		a, b := x, y
		for a > 0 {
			a, b = b%a, a
		}
		p := [2]int64{x / b, y / b}
		if _, ok := id[p]; !ok {
			id[p] = len(id)
		}
		return id[p]
	}
	n := r()
	type nb struct{ w, i int }
	g := make([][]nb, 2*n)
	for i := 1; i <= n; i++ {
		a,b,c,d := int64(r()), int64(r()), int64(r()), int64(r())
		v, w := genID(b*c, (a+b)*d), genID(b*(c+d), a*d)
		g[v] = append(g[v], nb{w, i})
		g[w] = append(g[w], nb{v, i})
	}

	ans := make([][]int, len(id))
	vis := make([]int8, len(id))
	var f func(int, int)
	f = func(v, p int) {
		vis[v] = 1
		for _, e := range g[v] {
			w, i := e.w, e.i
			if i == p || vis[w] == 2 {
				continue
			}
			if vis[w] == 1 {
				ans[v] = append(ans[v], i)
			} else {
				f(w, i)
				if len(ans[w])&1 > 0 {
					ans[w] = append(ans[w], i)
				} else {
					ans[v] = append(ans[v], i)
				}
			}
		}
		vis[v] = 2
	}
	for i, b := range vis {
		if b == 0 {
			f(i, 0)
		}
	}

	s:=0
	for _, ids := range ans {
		s += len(ids) / 2
	}
	Fprintln(out, s)
	for _, ids := range ans {
		for i := 1; i < len(ids); i += 2 {
			Fprintln(out, ids[i-1], ids[i])
		}
	}
}

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	id := map[[2]int64]int{}
	e := func(x, y int64) int {
		a, b := x, y
		for a > 0 {
			a, b = b%a, a
		}
		p := [2]int64{x/b, y/b}
		if _, ok := id[p]; !ok {
			id[p] = len(id)
		}
		return id[p]
	}
	var n, s int
	var a, b, c, d int64
	Fscan(in, &n)
	type nb struct{ w, i int }
	g := make([][]nb, 2*n)
	for i := 1; i <= n; i++ {
		Fscan(in, &a, &b, &c, &d)
		v, w := e(b*c, (a+b)*d), e(b*(c+d), a*d)
		g[v] = append(g[v], nb{w, i})
		g[w] = append(g[w], nb{v, i})
	}

	ds := make([][]int, len(id))
	vis := make([]int, len(id))
	var f func(int, int)
	f = func(v, p int) {
		vis[v] = 1
		for _, e := range g[v] {
			w,i:= e.w,e.i
			if i == p || vis[w] == 2 {
				continue
			}
			if vis[w] > 0 {
				ds[v] = append(ds[v], i)
			} else {
				f(w, i)
				if len(ds[w])&1 > 0 {
					ds[w] = append(ds[w], i)
				} else {
					ds[v] = append(ds[v], i)
				}
			}
		}
		vis[v] = 2
	}
	for i, b := range vis {
		if b == 0 {
			f(i, 0)
		}
	}

	for _, d := range ds {
		s += len(d) / 2
	}
	Fprintln(out, s)
	for _, d := range ds {
		for i := 0; i+1 < len(d); i += 2 {
			Fprintln(out, d[i], d[i+1])
		}
	}
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
type pvi struct {
	d, v int
	i    int
}
type hpi []*pvi

func (h hpi) Len() int             { return len(h) }
func (h hpi) Less(i, j int) bool   { return h[i].d < h[j].d }
func (h hpi) Swap(i, j int)        { h[i], h[j] = h[j], h[i]; h[i].i = i; h[j].i = j }
func (h *hpi) Push(v interface{})  { *h = append(*h, v.(*pvi)) }
func (h *hpi) Pop() interface{}    { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v }
func (h *hpi) push(d, id int) *pvi { p := &pvi{d, id, len(*h)}; heap.Push(h, p); return p }
func (h *hpi) pop() *pvi           { return heap.Pop(h).(*pvi) }
func (h *hpi) fix(i int)           { heap.Fix(h, i) }
func (h *hpi) remove(i int) *pvi   { return heap.Remove(h, i).(*pvi) }

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type edge struct{ v, w int }

	f := func(x, y int64) [2]int64 {
		g := gcd(x, y)
		return [2]int64{x / g, y / g}
	}
	var n int
	var a, b, c, d int64
	Fscan(in, &n)
	if n == 1 {
		Fprintln(out, 0)
		return
	}

	id := map[[2]int64]int{}
	es := make([]edge, 0, n)
	for i := 1; i <= n; i++ {
		Fscan(in, &a, &b, &c, &d)
		p := f(b*c, (a+b)*d)
		if _, ok := id[p]; !ok {
			id[p] = len(id)
		}
		q := f(b*(c+d), a*d)
		if _, ok := id[q]; !ok {
			id[q] = len(id)
		}
		es = append(es, edge{id[p], id[q]})
	}

	n = len(id)
	g := make([]map[int]int, n)
	for i := range g {
		g[i] = map[int]int{}
	}
	for i, e := range es {
		v, w := e.v, e.w
		g[v][i] = w
		g[w][i] = v
	}
	h := hpi{}
	pts := make([]*pvi, len(g))
	for i, vs := range g {
		if len(vs) > 1 {
			pts[i] = h.push(len(vs),i)
		}
	}

	ans := [][2]int{}

	for len(h) > 0  {
		if h[0].d < 2 {
			h.pop()
			continue
		}
		p := h[0]
		ids := [2]int{}
		c:=0
		for id, w := range g[p.v] {
			ids[c] = id
			delete(g[w], id)
			delete(g[p.v], id)
			if pts[w] != nil {
				pts[w].d--
				h.fix(pts[w].i)
			}

			c++
			if c == 2 {
				break
			}
		}
		if ids != [2]int{1,1} {
			ans = append(ans, ids)
		}
		h[0].d -= 2
		h.fix(pts[p.v].i)
	}

	Fprintln(out, len(ans))
	for _, p := range ans {
		Fprintln(out, p[0]+1, p[1]+1)
	}
}

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

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


package main

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

func solve() {
	n := readInt()
	a := make([]int, n)
	keys := make(map[int]bool)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}
	ans := 0
	for i := n - 1; i >= 0; i-- {
		if _, ok := keys[a[i]]; !ok {
			ans = a[i]
			keys[ans] = true
		}
	}
	fmt.Println(ans)
}

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

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

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
}

package main

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

var n int
var a [222222]int
var m map[int]bool
var res int

func main() {
	in := bufio.NewReader(os.Stdin)
	m = make(map[int]bool)

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

	for i := n-1; i >= 0; i-- {
		if m[a[i]] == false {
			m[a[i]] = true
			res = a[i]
		}
	}

	fmt.Printf("%d", res)
}

package main

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

var n, ans int
var a [200005]int
var met [200005]bool

func main() {
	fmt.Scanf("%d", &n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++{
		a[i], _ = strconv.Atoi(scanner.Text())
		//fmt.Println(a[i])
	}
	for i := n-1; i >= 0; i--{
		if !met[a[i]]{
			ans = a[i]
		}
		met[a[i]] = true
	}
	fmt.Println(ans)
}

package main;
import (
    "fmt"
    "os"
    "bufio"
)
var (
    n int
    a [222222]int
    m map[int]int
    res int
)

func main() {
	in := bufio.NewReader(os.Stdin)
	m = make(map[int]int)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	for i := n-1; i >= 0; i-- {
		if m[a[i]] == 0 {
			m[a[i]] = 1
			res = a[i]
		}
	}

	fmt.Printf("%d", res)
}

package main

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

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	pauses := map[int]int{}
	firstCantina := 0
	for i := 0; scanner.Scan(); i++ {
		cantina, _ := strconv.Atoi(scanner.Text())
		pauses[cantina] = n - i

		if i == 0 {
			firstCantina = cantina
		}
	}

	maxCantina := firstCantina
	maxPause := pauses[maxCantina]
	for c, p := range pauses {
		if p > maxPause {
			maxPause = p
			maxCantina = c
		}
	}

	fmt.Println(maxCantina)
}

package main;
import (
    "fmt"
)
var (
    n int
    a [222222]int
    m map[int]int
    res int
)

func main() {
	m = make(map[int]int)
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	for i := n-1; i >= 0; i-- {
		if m[a[i]] == 0 {
			m[a[i]] = 1
			res = a[i]
		}
	}

	fmt.Printf("%d", res)
}

package main

import(
	"fmt"
	//"os"
	//"strings"
)

var n, ans int
var a [200005]int
var met [200005]bool

func main() {
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++{
		fmt.Scanf("%d", &a[i])
	}
	for i := n-1; i >= 0; i--{
		if !met[a[i]]{
			ans = a[i]
		}
		met[a[i]] = true
	}
	fmt.Println(ans)
}

package main

import(
	"fmt"
	//"os"
	//"strings"
)

func main() {
	var n, ans int
	var a [200005]int
	var met [200005]bool
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++{
		fmt.Scanf("%d", &a[i])
	}
	for i := n-1; i >= 0; i--{
		if !met[a[i]]{
			ans = a[i]
		}
		met[a[i]] = true
	}
	fmt.Println(ans)
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"sync"
)
var a [100005]int
func main() {
	//var n, d, t, i, cas int
	for cas := ReadInt(); cas >0; cas-- {
		var maxx, ans int
		n:=ReadInt()
		d:=ReadInt()
		for i := 1; i <= n; i++ {
			a[i]=ReadInt()
			maxx = max(a[i], maxx)
			if a[i] == d {
				ans = 1
			}
		}
		if ans == 0 {
			tmp  := (d + maxx - 1) / maxx
			ans = max(tmp, 2)
		}
		fmt.Println(ans)
	}
}
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
}
var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.ParseInt(intStr, 10, 32)
	return int(i)
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		arrs := readLine(scanner)
		arr := strings.Split(string(arrs), " ")
		distance, _ := strconv.ParseUint(arr[1], 10, 64)
		arrs = readLine(scanner)
		arr = strings.Split(string(arrs), " ")
		bigest := uint64(0)
		flag := false
		for _, c := range arr {
			ai, _ := strconv.ParseUint(c, 10, 64)
			if ai > bigest {
				bigest = ai
			}
			if distance == ai {
				fmt.Println(1)
				flag = true
				break
			}
		}
		if flag {
			continue
		}
		result := uint64(0)
		if distance < bigest {
			result = 2
		} else if distance%bigest == 0 {
			result = distance / bigest
		} else {
			result = distance/bigest + 1
		}
		fmt.Println(result)
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/problemset/problem/1307/B
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, x int
	A    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x = ReadInt2()
		A = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	ans := INF_BIT30
	for _, a := range A {
		if x%a == 0 {
			ChMin(&ans, x/a)
		} else {
			q := x / a
			if q > 0 {
				ChMin(&ans, q+1)
			} else {
				ChMin(&ans, 2)
			}
			// ChMin(&ans, x/a)
		}
	}
	fmt.Println(ans)
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

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

/*********** 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 "fmt"
import "os"
import "bufio"
import "strings"
import "strconv"
//~ import "sort"

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    capacity := 5000 * 1024
    scanner.Buffer(make([]byte, capacity), capacity)
    scanner.Scan()
    line := scanner.Text()
    t, _ := strconv.Atoi(line)
    for i := 0; i < t; i++ {
        scanner.Scan()
        line = scanner.Text()
        parts := strings.Split(line, " ")
        n, _ := strconv.Atoi(parts[0])
        x, _ := strconv.Atoi(parts[1])

        a := make([]int, n)
        scanner.Scan()
        line = scanner.Text()
        parts = strings.Split(line, " ")
        for j := 0; j < n; j++ {
            a[j], _ = strconv.Atoi(parts[j]);
        }
        fmt.Println(solve(a, x))
    }
}

func solve(a []int, x int) int {
    //~ fmt.Println(a, x)

    var max int
    for j := 0; j < len(a); j++ {
        if a[j] > max {
            max = a[j];
        }
    }

    if x < max {
        for _, v := range a {
            if v == x {
                return 1
            }
        }
        return 2
    } else {
        if x % max == 0 {
            return x / max
        } else {
            return (x / max) + 1
        }
    }
}

package main

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

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

	var T int
	fmt.Fscanf(reader, "%d\n", &T)

	for t := 0; t < T; t++ {
		var n, x int
		fmt.Fscanf(reader, "%d %d\n", &n, &x)

		ans := (1 << 30)
		for i := 0; i < n; i++ {
			var e int
			fmt.Fscanf(reader, "%d", &e)

			l := max(0, x-2*e)
			y := (l + e - 1) / e
			w := x - e*y

			req := y
			if w == e {
				req++
			} else {
				req += 2
			}

			ans = min(ans, req)
		}
		fmt.Fscanf(reader, "\n")

		fmt.Fprintf(writer, "%d\n", ans)
	}
}

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

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

	var t, n, x, v int
	for Fscan(in, &t); t > 0; t-- {
		mx := 0
		found := false
		for Fscan(in, &n, &x); n > 0; n-- {
			if Fscan(in, &v); v > mx {
				mx = v
			}
			if v == x {
				found = true
			}
		}
		if found {
			Fprintln(out, 1)
		} else if mx > x {
			Fprintln(out, 2)
		} else {
			Fprintln(out, (x-1)/mx+1)
		}
	}
}

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

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)
	T := NextInt()
	// a := make([]int, 100010)
	for t := 0; t < T; t++ {
		n := NextInt()
		x := NextInt()
		var res, cur int
		for i := 0; i < n; i++ {
			r := NextInt()
			if r <= x {
				cur = (x - r) / r
				if (x-r)%r != 0 {
					cur++
				}
			} else {
				cur = (r - x) / r
				if (r-x)%r != 0 {
					cur++
				}
			}

			if i == 0 || cur+1 < res {
				res = cur + 1
			}
		}
		fmt.Fprintln(out, res)
	}
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	var cases int
	fmt.Scanf("%d\n", cases)
	for i := 0; i < cases; i++ {
		arrs := readLine(scanner)
		arr := strings.Split(string(arrs), " ")
		distance, _ := strconv.ParseUint(arr[1], 10, 64)
		arrs = readLine(scanner)
		arr = strings.Split(string(arrs), " ")
		bigest := uint64(0)
		flag := false
		for _, c := range arr {
			ai, _ := strconv.ParseUint(c, 10, 64)
			if ai > bigest {
				bigest = ai
			}
			if distance == ai {
				fmt.Println(1)
				flag = true
				break
			}
		}
		if flag {
			continue
		}
		result := uint64(0)
		if distance < bigest {
			result = 2
		} else if distance%bigest == 0 {
			result = distance / bigest
		} else {
			result = distance/bigest + 1
		}
		fmt.Println(result)
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			// fmt.Println(string(result))
			break
		}
	}
	return result
}

package main

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

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

	var t, n, x, v int
	for Fscan(in, &t); t > 0; t-- {
		mx := 0
		for Fscan(in, &n, &x); n > 0; n-- {
			if Fscan(in, &v); v > mx {
				mx = v
			}
		}
		if mx > x {
			Fprintln(out, 2)
		} else {
			Fprintln(out, (x-1)/mx+1)
		}
	}
}

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


package main

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

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

	var T int
	var n, a, b int64
	f := func() bool {
		if a == 1 {
			return (n-1)%b == 0
		}
		for i := int64(1); i <= n; i *= a {
			if (n-i)%b == 0 {
				return true
			}
		}
		return false
	}
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &a, &b)
		if f() {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

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

package main

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

	}
	return m
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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, a, b int64
		fmt.Fscan(input, &n, &a, &b)
		if b == 1 {
			fmt.Println("YES")
		} else {
			if a == 1 {
				if n%b == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			} else {
				var begin, Aim int64
				Aim = n
				begin = 1
				ww := 0
				for i := 0; Aim-begin > -1; i++ {
					qq := Aim - begin
					if qq%b == 0 {
						ww = 1
						break
					} else {
						begin = begin * a
					}
				}
				if ww == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("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 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-- {
		n, a, b := sint64(), sint64(), sint64()
		printf("%s\n", sol(n, a, b))
	}
}

func sol(n, a, b int64) string {
	if a == 1 {
		if (n-1)%b == 0 {
			return "Yes"
		}
		return "No"
	}
	curr := int64(1)
	for curr <= n {
		if (n-curr)%b == 0 {
			return "Yes"
		}
		curr = curr * a
	}
	return "No"
}

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 n, a, b int64
		_, _ = fmt.Fscan(in, &n, &a, &b)

		var ans bool

		for ap := int64(1); ap <= n; ap *= a {
			if (n-ap)%b == 0 {
				ans = true
				break
			}

			if a == 1 {
				break
			}
		}

		if ans {
			_, _ = fmt.Fprintln(out, "Yes")
		} else {
			_, _ = fmt.Fprintln(out, "No")
		}

	}

	_ = out.Flush()
}

package main

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

// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

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

	for i := 0; i < testCount; i++ {
		var n, a, b int64
		fmt.Fscan(in, &n, &a, &b)

		var yes bool
		var sumG int64 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}
		}

		if yes {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

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

	for i := 0; i < testCount; i++ {
		var n, a, b int64
		fmt.Fscan(in, &n, &a, &b)

		var yes bool
		var sumG int64 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}
		}

		if yes {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int64, 0, 3)

	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.ParseInt(p, 10, 64)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		var yes bool
		var sumG int64 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}
		}

		if yes {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

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

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

	for i := 0; i < testCount; i++ {
		yes := false
		var n, a, b int64

		_, _ = fmt.Fscan(in, &n, &a, &b)

		var sumG int64 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}

			if a == 1 {
				break
			}
		}

		if yes {
			_, _ = fmt.Fprintln(out, "Yes")
		} else {
			_, _ = fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

var in *bufio.Reader

func solve() {
	var n, a, b int64
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &a)
	fmt.Fscan(in, &b)

	var x int64 = 1
	for x <= n {
		if x%b == n%b {
			fmt.Println("Yes")
			return
		}
		if a == 1 {
			break
		}
		x *= a
	}
	fmt.Println("No")
}

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

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

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

package main

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

const N = int(1e5 + 10)

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()
	t := 1
	t = io.NextInt()

	for tt := 0; tt < t; tt++ {
		solve := func() {
			n, a, b := io.NextInt(), io.NextInt(), io.NextInt()
			val := int64(1)
			for {
				if val > int64(n) {
					break
				}
				if (int64(n)-val)%int64(b) == 0 {
					io.Println("Yes")
					return
				}
				val *= int64(a)
				if a == 1 {
					break
				}
			}
			io.Println("No")
		}
		solve()
	}
}

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

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

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

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func main() {
	_r, _w := os.Stdin, os.Stdout
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var solve func()
	solve = func() {
		var a, b, n int64
		Fscan(in, &n, &a, &b)
		if n == 1 || b == 1 {
			Fprintln(out, "Yes")
			return
		}
		if a == 1 {
			if n%b == 1 {
				Fprintln(out, "Yes")
			} else {
				Fprintln(out, "No")
			}
			return
		}
		var base int64 = 1
		for base <= n {
			if base%b == n%b {
				Fprintln(out, "Yes")
				return
			}
			base *= a
		}
		Fprintln(out, "No")
	}
	var T int = 1
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}

}

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 n, a, b int64
		Fscan(in, &n, &a, &b)

		if a == 1 {
			return (n-1)%b == 0
		}
		for i := int64(1); i <=n; i*=a {
			if (n-i)%b ==0 {
				return true
			}
		}

		return
	}

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

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

package main

// 1542B: Plus and Multiply

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi := 0; oi < k; oi++ {
		// if number is divisible by a, then divide by a; else subtract by b
		// the final result shall be 1
		pln,_ := Readln(reader)
		ln := strings.Split(pln, " ")
		n,_ := strconv.Atoi(ln[0])
		a,_ := strconv.Atoi(ln[1])
		b,_ := strconv.Atoi(ln[2])

		if b==1 {
			fmt.Println("yes")
			continue
		}
		if a==1 {
			if (n-1) % b ==0 {
				fmt.Println("yes")
				continue
			}
			fmt.Println("no")
			continue
		}

		//pretty much in the form of: a**p + q*b ?

		ok := false
		i:= float64(0)
		for float64(n)- math.Pow(float64(a),i) >= 0 {
			if int(float64(n)- math.Pow(float64(a),i)) % b ==0 {
				ok = true
				//fmt.Println(i)
				break
			}
			i++
		}

		if ok{
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}

	}

}

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() int64 {
	var res int64
	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)
	t := io.ReadInt()
	for ; t > 0; t-- {
		sl := io.ReadIntSlice(3)
		n, a, b := int64(sl[0]), int64(sl[1]), int64(sl[2])
		st := int64(1)
		done := false
		for st <= n {
			if (n - st) % b == 0 {
				io.Println("Yes")
				done = true
				break
			}
			st *= a
			if a == 1 {
				break
			}
		}
		if !done {
			io.Println("No")
		}
	}
}

package main

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

const (
	MOD int64 = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

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

	n, a, b int64
	res bool
)

func main() {
	initBuffer()
	var t int = 1
	t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {
	res = false
}

func input() {
	n = getInt64()
	a = getInt64()
	b = getInt64()
}

func count() {
	if a == 1 {
		res = (n - 1) % b == 0
		return
	}
	var i int64 = 1
	for {
		if (n - i) % b == 0 {
			res = true
			return
		}
		i *= a
		if i > n {
			return
		}
	}
}

func output() {
	yes(res, false)
}

func test() {
	fmt.Print()
}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
		res2 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	var res [33]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 33
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 33 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	if n1 > n2 {
		return n1
	}
	return n2
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(arr[ind])
	out.WriteByte(NL)
	return res
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

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

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(a, b, n int) bool {
	if a == 1 {
		return (n - 1) % b == 0
	}

	B := int64(b)
	N := int64(n)
	A := int64(a)

	var t int64 = 1

	for t <= N {

		if N%B == t%B {
			return true
		}
		t *= A

	}
	return false
}

package main

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

// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

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

	for i := 0; i < testCount; i++ {
		var n, a, b int32
		fmt.Fscan(in, &n, &a, &b)

		var prev int32
		var yes bool
		var sumG int32 = 1
		for ; sumG <= n; sumG *= a {
			if prev > sumG {
				break
			}

			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}

			prev = sumG
		}

		if yes {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

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

	for i := 0; i < testCount; i++ {
		var n, a, b int32
		fmt.Fscan(in, &n, &a, &b)

		var prev int32
		var yes bool
		var sumG int32 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 || prev > sumG {
				break
			}

			prev = sumG
		}

		if yes {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

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

	for i := 0; i < testCount; i++ {
		var n, a, b int64
		fmt.Fscan(in, &n, &a, &b)

		var yes bool
		var sumG int64 = 1
		for ; sumG < n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}
		}

		if yes {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}

	_ = out.Flush()
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int64, 0, 3)

	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.ParseInt(p, 10, 64)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 && a != 1 {
			fmt.Println("Yes")
			continue
		}

		var yes bool
		var sumG int64 = 1
		for ; sumG <= n; sumG *= a {
			if (n-sumG)%b == 0 {
				yes = true
				break
			}
			if a == 1 {
				break
			}
		}

		if yes {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int64, 0, 3)
next:
	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.ParseInt(p, 10, 64)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 && a != 1 {
			fmt.Println("Yes")
			continue
		}

		var sumG int64 = 1
		for ; sumG < n; sumG *= a {
			if (n-sumG)%b == 0 {
				fmt.Println("Yes")
				continue next
			}
			if a == 1 {
				fmt.Println("No")
				continue next
			}
		}

		fmt.Println("No")
	}
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int64, 0, 3)
next:
	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.ParseInt(p, 10, 64)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 && a != 1 {
			fmt.Println("Yes")
			continue
		}

		if n%b == 1 || b == 1 {
			fmt.Println("Yes")
			continue
		}

		var sumG int64 = 1
		for ; sumG < n; sumG *= a {
			if (n-sumG)%b == 0 {
				fmt.Println("Yes")
				continue next
			}
			if a == 1 {
				fmt.Println("No")
				continue next
			}
		}

		fmt.Println("No")
	}
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int64, 0, 3)
next:
	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.ParseInt(p, 10, 64)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 && a != 1 {
			fmt.Println("Yes")
			continue
		}

		if n%b == 1 || b == 1 {
			fmt.Println("Yes")
			continue
		}

		if a == 1 {
			fmt.Println("No")
			continue
		}

		var sumG, prevSum int64 = 1, 1
		for sumG < n {
			prevSum = sumG
			sumG = prevSum * a

			if (n-sumG)%b == 0 {
				fmt.Println("Yes")
				continue next
			}
		}

		fmt.Println("No")
	}
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

	inputList := make([]int, 0, 3)

	for i := 0; i < testCount; i++ {
		inputList = inputList[:0]

		scanner.Scan()
		input := scanner.Text()

		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.Atoi(p)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 && a != 1 {
			fmt.Println("Yes")
			continue
		}

		if n%b == 1 || b == 1 {
			fmt.Println("Yes")
			continue
		}

		if a == 1 {
			fmt.Println("No")
			continue
		}
		var yes bool
		sumG := 1
		prevSum := 1
		for sumG < n {
			prevSum = sumG
			sumG = prevSum * a

			if (n-sumG)%b == 0 {
				break
			}
		}

		if yes {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

// если не проходят базовые случаи
// i - номер случая
// посчитать сумму геометрической прогрессии n / (i * a) элемента, проверить входит ли в арифмитическую прогрессию
// посчитать сумму арифимитической прогрессии n - (i * b)
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

next:
	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input := scanner.Text()

		inputList := make([]int, 0, 3)
		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.Atoi(p)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 {
			fmt.Println("Yes")
			continue
		}

		if n%b == 1 {
			fmt.Println("Yes")
			continue
		}

		for i := 1; i < a; i++ {
			sumG := n / (i * a)
			if sumG/b > 0 && sumG%b == 1 {
				fmt.Println("Yes")
				continue next
			}
		}

		fmt.Println("No")
	}
}

package main

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

// если не проходят базовые случаи
// посчитать сумму геометрической прогрессии n / ((a - 1) * a) элемента, проверить входит ли в арифмитическую прогрессию
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	testCount, _ := strconv.Atoi(scanner.Text())

next:
	for i := 0; i < testCount; i++ {
		scanner.Scan()
		input := scanner.Text()

		inputList := make([]int, 0, 3)
		for _, p := range strings.Split(input, " ") {
			o, _ := strconv.Atoi(p)
			inputList = append(inputList, o)
		}

		n, a, b := inputList[0], inputList[1], inputList[2]

		if n%a == 0 {
			fmt.Println("Yes")
			continue
		}

		if n%b == 1 {
			fmt.Println("Yes")
			continue
		}

		for i := 0; i < a; i++ {
			sum := n / ((a - i) * a)
			if sum / b > 0 && sum%b == 1 {
				fmt.Println("Yes")
				continue next
			}
		}

		fmt.Println("No")
	}
}

package main

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

var in *bufio.Reader

func solve() {
	var n, a, b int64
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &a)
	fmt.Fscan(in, &b)

	var x int64 = 1
	for x < n {
		if x%b == n%b {
			fmt.Println("Yes")
			return
		}
		if a == 1 {
			break
		}
		x *= a
	}
	fmt.Println("No")
}

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

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

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

package main

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

const N = int(1e5 + 10)

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()
	t := 1
	t = io.NextInt()

	for tt := 0; tt < t; tt++ {
		solve := func() {
			n, a, b := io.NextInt(), io.NextInt(), io.NextInt()
			val := int64(1)
			for {
				val *= int64(a)
				if val > int64(n) {
					break
				}
				if (int64(n)-val)%int64(b) == 0 {
					io.Println("Yes")
					return
				}
				if a == 1 {
					break
				}
			}
			io.Println("No")
		}
		solve()
	}
}

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

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

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

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

const N = int(1e5 + 10)

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()
	t := 1
	t = io.NextInt()

	for tt := 0; tt < t; tt++ {
		solve := func() {
			n, a, b := io.NextInt(), io.NextInt(), io.NextInt()
			val := int64(1)
			for i := 1; i < 30; i++ {
				val *= int64(a)
				if val > int64(n) {
					break
				}
				if (int64(n)-val)%int64(b) == 0 {
					io.Println("Yes")
					return
				}
			}
			io.Println("No")
		}
		solve()
	}
}

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

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

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

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func main() {
	_r, _w := os.Stdin, os.Stdout
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var solve func()
	solve = func() {
		var a, b, n int64
		Fscan(in, &n, &a, &b)
		if n == 1 || b == 1 {
			Fprintln(out, "Yes")
			return
		}
		if a == 1 {
			if n%b == 1 {
				Fprintln(out, "Yes")
			} else {
				Fprintln(out, "No")
			}
			return
		}
		var base int64 = 1
		for base < n {
			if base%b == n%b {
				Fprintln(out, "Yes")
				return
			}
			base *= a
		}
		Fprintln(out, "No")
	}
	var T int = 1
	Fscan(in, &T)
	for i := 0; i < T; i++ {
		solve()
	}

}

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 n, a, b int64
		Fscan(in, &n, &a, &b)

		if a == 1 {
			return (n-1)%b == 0
		}
		for i := a; i <=n; i*=a {
			if (n-i)%b ==0 {
				return true
			}
		}

		return
	}

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

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

package main

// 1542B: Plus and Multiply

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi := 0; oi < k; oi++ {
		// if number is divisible by a, then divide by a; else subtract by b
		// the final result shall be 1
		pln,_ := Readln(reader)
		ln := strings.Split(pln, " ")
		n,_ := strconv.Atoi(ln[0])
		a,_ := strconv.Atoi(ln[1])
		b,_ := strconv.Atoi(ln[2])

		if b==1 {
			fmt.Println("yes")
			continue
		}
		if a==1 {
			if (n-1) % b ==0 {
				fmt.Println("yes")
				continue
			}
			fmt.Println("no")
			continue
		}

		//pretty much in the form of: a**p + q*b ?

		ok := false
		i:= float64(0)
		for float64(n)- math.Pow(float64(a),i) > 0 {
			if int(float64(n)- math.Pow(float64(a),i)) % b ==0 {
				ok = true
				//fmt.Println(i)
				break
			}
			i++
		}

		if ok{
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}

	}

}

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() int64 {
	var res int64
	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)
	t := io.ReadInt()
	for ; t > 0; t-- {
		sl := io.ReadIntSlice(3)
		n, a, b := int64(sl[0]), int64(sl[1]), int64(sl[2])
		st := int64(1)
		done := false
		for st < n {
			if (n - st) % b == 0 {
				io.Println("Yes")
				done = true
				break
			}
			st *= a
			if a == 1 {
				break
			}
		}
		if !done {
			io.Println("No")
		}
	}
}

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 n, a, b int64
		_, _ = fmt.Fscan(in, &n, &a, &b)

		var ans bool

		if a == 1 {
			_, _ = fmt.Fprintln(out, "Yes")
			continue
		}

		for ap := int64(1); ap <= n; ap *= a {
			if (n-ap)%b == 0 {
				ans = true
				break
			}
		}

		if ans {
			_, _ = fmt.Fprintln(out, "Yes")
		} else {
			_, _ = fmt.Fprintln(out, "No")
		}

	}

	_ = out.Flush()
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

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

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(a, b, n int) bool {
	if a == 1 {
		return n%b == 1
	}

	B := int64(b)
	N := int64(n)
	A := int64(a)

	var t int64 = 1

	for t <= N {

		if N%B == t%B {
			return true
		}
		t *= A

	}
	return false
}


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

func main(){
    in := bufio.NewReader(os.Stdin);
    var n,m,K int
    fmt.Fscanf(in,"%d%d%d\n",&n,&m,&K)

    table := [1e6+1]int{};
    for i:=0;i<m;i++{
        var x int
        fmt.Fscanf(in,"%d",&x)
        //fmt.Println(x)
        table[x]=1
    }
    fmt.Fscanf(in,"\n")
    cur:=1
    var completed bool
    for i:=0;i<K;i++{
        var u,v int
        fmt.Fscanf(in,"%d%d\n",&u,&v)
        if completed {
            continue
        }
        if table[cur]==1 {
            completed = true
        }else{
            if cur==u||cur==v{
                if cur==u{
                    cur=v
                }else{
                    cur=u
                }
            }
        }
    }
    fmt.Println(cur)
}

package main

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

func main() {
	sc := NewScanner()
	_, _, K := sc.NextInt(), sc.NextInt(), sc.NextInt()
	h := sc.NextMap()
	b := 1

	for i := 0; i < K; i++ {
		if h[b] {
			fmt.Println(b)
			return
		}

		u, v := sc.NextInt(), sc.NextInt()

		if b == u {
			b = v
		} else if b == v {
			b = u
		}

	}
	fmt.Println(b)

}

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

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

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

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

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

	return mp
}

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

package main

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

func solve() {
	n := readInt()
	m := readInt()
	k := readInt()
	h := make([]bool, n)
	for i := 0; i < m; i++ {
		h[readInt()-1] = true
	}
	pos := 0
	if !h[pos] {
		for i := 0; i < k; i++ {
			u := readInt() - 1
			v := readInt() - 1
			if pos == u {
				pos = v
			} else if v == pos {
				pos = u
			}

			if h[pos] {
				break
			}
		}
	}
	fmt.Println(pos + 1)
}

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

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

// 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
}

package main

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}

	N := io.NextInt()
	M := io.NextInt()
	K := io.NextInt()
	H := io.NextIntArray(M)

	U := make([]int, K)
	V := make([]int, K)
	for i := 0; i < K; i++ {
		U[i] = io.NextInt()
		V[i] = io.NextInt()
	}

	hole := make([]bool, N + 1)
	for _, pos := range H {
		hole[pos] = true
	}

	pos := 1
	for i := 0; i < K; i++ {
		if hole[pos] {
			break
		}
		if pos == U[i] {
			pos = V[i]
		} else if pos == V[i] {
			pos = U[i]
		}
	}
	io.Printf("%d\n", pos)

	io.FlushOutput()
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if (c == '-') {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if (c == '-') {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

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

package main
import "fmt"

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

    table := [1e6+1]int{};
    for i:=0;i<m;i++{
        var x int
        fmt.Scanf("%d\n",&x)
        table[x]=1
    }
    cur:=1
    var completed bool
    for i:=0;i<K;i++{
        var u,v int
        fmt.Scanf("%d%d\n",&u,&v)
        if completed {
            continue
        }
        if table[cur]==1 {
            completed = true
        }else{
            if cur==u{
                cur=v
            }else{
                cur=u
            }
        }
    }
    fmt.Println(cur)
}

package main
import "fmt"

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

    table := [1e6+1]int{};
    for i:=0;i<m;i++{
        var x int
        fmt.Scanf("%d\n",&x)
        table[x]=1
    }
    cur:=1
    var completed bool
    for i:=0;i<K;i++{
        var u,v int
        fmt.Scanf("%d%d\n",&u,&v)
        if completed {
            continue
        }
        if table[cur]==1 {
            completed = true
        }else{
            if cur==u||cur==v{
                if cur==u{
                    cur=v
                }else{
                    cur=u
                }
            }
        }
    }
    fmt.Println(cur)
}

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

func main(){
    in := bufio.NewReader(os.Stdin);
    var n,m,K int
    fmt.Fscanf(in,"%d%d%d\n",&n,&m,&K)

    table := [1e6+1]int{};
    for i:=0;i<m;i++{
        var x int
        fmt.Fscanf(in,"%d",&x)
        //fmt.Println(x)
        table[x]=1
    }
    fmt.Scanf("\n")
    cur:=1
    var completed bool
    for i:=0;i<K;i++{
        var u,v int
        fmt.Fscanf(in,"%d%d\n",&u,&v)
        if completed {
            continue
        }
        if table[cur]==1 {
            completed = true
        }else{
            if cur==u||cur==v{
                if cur==u{
                    cur=v
                }else{
                    cur=u
                }
            }
        }
    }
    fmt.Println(cur)
}

package main
import "fmt"

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

    table := [1e6+1]int{};
    for i:=0;i<m;i++{
        var x int
        fmt.Scanf("%d",&x)
        //fmt.Println(x)
        table[x]=1
    }
    cur:=1
    var completed bool
    for i:=0;i<K;i++{
        var u,v int
        fmt.Scanf("%d%d\n",&u,&v)
        if completed {
            continue
        }
        if table[cur]==1 {
            completed = true
        }else{
            if cur==u||cur==v{
                if cur==u{
                    cur=v
                }else{
                    cur=u
                }
            }
        }
    }
    fmt.Println(cur)
}

package main

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

func main() {
	sc := NewScanner()
	_, _, K := sc.NextInt(), sc.NextInt(), sc.NextInt()
	h := sc.NextMap()
	b := 1

	for i := 0; i < K; i++ {
		u, v := sc.NextInt(), sc.NextInt()
		if h[u] {
			fmt.Println(u)
			return
		}
		if h[v] {
			fmt.Println(v)
			return
		}

		if b == u {
			b = v
		} else {
			b = u
		}
	}
	fmt.Println(b)

}

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

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

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

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

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

	return mp
}

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

package main

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

func main() {
	sc := NewScanner()
	_, _, K := sc.NextInt(), sc.NextInt(), sc.NextInt()
	h := sc.NextMap()
	b := 1

	for i := 0; i < K; i++ {
		u, v := sc.NextInt(), sc.NextInt()
		if h[u] {
			fmt.Println(u)
			return
		}
		if h[v] {
			fmt.Println(v)
			return
		}

		if b == u {
			b = v
		} else if b == v {
			b = u
		}
	}
	fmt.Println(b)

}

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

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

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

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

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

	return mp
}

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


package main

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

// 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)
		s := 0
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			s+=a[i]
		}
		if s ==0 {
			Fprintln(out, "NO")
			return
		}
		sort.Ints(a)
		Fprintln(out, "YES")
		if s < 0 {
			for _, v := range a {
				Fprint(out, v, " ")
			}
		} else {
			for i := len(a) - 1; i >= 0; i-- {
				Fprint(out, a[i], " ")
			}
		}
		Fprintln(out)

		return
	}

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

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

func solve(n int, a []int) {
	sum := Sum(a...)
	if sum == 0 {
		Println("NO")
		return
	}
	Println("YES")
	if sum > 0 {
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
	} else {
		sort.Ints(a)
	}
	for i := 0; i < n; i++ {
		if i > 0 {
			Print(" ")
		}
		Print(a[i])
	}
	Println()
}

func Sum(slice ...int) int {
	sum := 0
	for _, v := range slice {
		sum += v
	}
	return sum
}

var writer = bufio.NewWriter(os.Stdout)

func Print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func Printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }
func Println(a ...interface{})               { fmt.Fprintln(writer, a...) }

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


package main

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

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

	var n, m int
	Fscan(in, &n, &m)
	if m < n-1 {
		Fprint(out, "Impossible")
		return
	}
	ans := make([][2]int, 0, m)
o:
	for i := 1; i < n; i++ {
		for j := i + 1; j <= n; j++ {
			if gcd(i, j) == 1 {
				ans = append(ans, [2]int{i, j})
				if len(ans) == m {
					break o
				}
			}
		}
	}
	if len(ans) < m {
		Fprint(out, "Impossible")
		return
	}
	Fprintln(out, "Possible")
	for _, e := range ans {
		Fprintln(out, e[0], e[1])
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func scanf(f string, a ...interface{}) {
	fmt.Fscanf(reader, f, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}
func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}
func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}
func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}
// head

func main() {
	defer writer.Flush()
	var n, m int
	scan(&n, &m)
	if m < n - 1 {
		println("Impossible")
		return
	}
	edges := make([][]int, n + 1)
	edges[1] = append(edges[1], 0)
	cnt := 0
	for i := 1; i < n + 1; i++ {
		for _, j := range edges[i] {
			for k := 1;;k++ {
				t := j + k*i
				if t <= i {
					continue
				}
				if t > n {
					break
				}
				edges[t] = append(edges[t], i)
				cnt++
				if cnt >= m {
					goto output
				}
			}
		}
	}
	output:
	if cnt < m {
		println("Impossible")
		return
	}
	println("Possible")
	for i := 2; i < n + 1; i++ {
		for _, j := range edges[i] {
			println(i, j)
		}
	}
}