package main

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

func main() {
	var n int
	var total = math.MaxInt32
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	arrNm := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrNm[0])
	tet := make([]int,n)
	line, _ = reader.ReadString('\n')
	arrS := strings.Split(strings.TrimSpace(line), " ")
	for _,v := range arrS {
		tmp, _ := strconv.Atoi(v)
		tet[tmp-1]++
	}
	for _, v:= range tet{
		if v<total{
			total=v
		}
	}
	if total == math.MaxInt32{
		fmt.Println(0)
	} else {
		fmt.Println(total)
	}
}

package main

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

func main() {
	var n, m int
	counter := map[int]int{}
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d\n", &n, &m)
	for i := 0; i < m; i++ {
		var x int
		fmt.Fscanf(stdin, "%d", &x)
		counter[x]++
	}
	// find min number
	minX := 1001
	for col := 1; col <= n; col++ {
		if counter[col] < minX {
			minX = counter[col]
		}
	}
	fmt.Println(minX)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var n, m int
	fmt.Sscanf(scanner.Text(), "%d %d", &n, &m)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	tetris := make([]int, n)
	for _, v := range s {
		sq, _ := strconv.Atoi(v)
		tetris[sq-1]++
	}
	min := m
	for i := 0; i < len(tetris); i++ {
		if tetris[i] < min {
			min = tetris[i]
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[int]int)

	for i := 0; i < colNum; i++ {
		tetris[i + 1] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		tetris[j]++
	}

	min := tetris[1]
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}

	fmt.Println(min)
}

package main

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

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

// IO helper functions

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// IO functions

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

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

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

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

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

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

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

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

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

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

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

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

// Simple math functions

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer Flush()

	n := readi()
	a := make([]int, n)
	m := readi()
	for i := 0; i < m; i++ {
		a[readi()-1]++
	}
	ans := a[0]
	for _, v := range a {
		ans = min(ans, v)
	}
	println(ans)
}

package main

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

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

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

func main() {
    defer writer.Flush()

    var n, m int
    scanf("%d%d\n", &n, &m);
    var cnt [1005]int
    for i := 0; i < m; i++ {
        var a int
        scanf("%d", &a);
        cnt[a - 1] += 1
    }
    var ans = int(^uint(0) >> 1)
    for i := 0; i < n; i++ {
        ans = min(ans, cnt[i])
    }
    printf("%d\n", ans)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int32
	fmt.Scanf("%d %d", &n, &m)
	var i int32
	square := make([]int32, n)
	var ans int32 = 1000;
	var pos int32
	for i = 0; i < m; i++{
		fmt.Scan(&pos)
		square[pos - 1]++
	}
	for i = 0; i < n; i++ {
		if square[i] < ans {
			ans = square[i]
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	var a [1002]int

	fmt.Scanf("%d %d\n", &n, &m)

	for i := 1; i <= n; i++ {
		a[i] = 0
	}

	score := 0
	num1 := 0

	var temp int
	for i := 0; i < m; i++ {
		fmt.Scanf("%d", &temp)

		a[temp]++

		if a[temp] == 1 {
			num1++
		}

		if num1 == n {
			score++

			for j := 1; j <= n; j++ {
				a[j]--

				if a[j] == 0 {
					num1--
				}
			}
		}
	}

	fmt.Println(score)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	var a [1002]int

	fmt.Scanf("%d %d\n", &n, &m)

	for i := 1; i <= n; i++ {
		a[i] = 0
	}

	score := m

	var temp int
	for i := 0; i < m; i++ {
		fmt.Scanf("%d", &temp)

		a[temp]++
	}

	for i := 1; i <= n; i++ {
		if score > a[i] {
			score = a[i]
		}
	}

	fmt.Println(score)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func nextInt() int {
	in.Scan()
	r := 0
	for _, c := range in.Bytes() {
		r *= 10
		r += int(c - '0')
	}
	return r
}

func main() {
	in.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	a := make([]int, n)
	for ; m > 0; m-- {
		a[nextInt()-1]++
	}
	r := a[0]
	for _, v := range a[1:] {
		if r > v {
			r = v
		}
	}
	fmt.Println(r)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	f := map[int]int{}
	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		var v int
		fmt.Scan(&v)
		f[v]++
	}
	ans := m
	for i := 1; i <= n; i++ {
		if f[i] < ans {
			ans = f[i]
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	f := map[int]int{}
	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		var v int
		fmt.Scan(&v)
		f[v]++
	}
	ans := n + 1
	for i := 1; i <= n; i++ {
		if f[i] < ans {
			ans = f[i]
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	var n, m int
	counter := map[int]int{}
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d\n", &n, &m)
	for i := 0; i < m; i++ {
		var x int
		fmt.Fscanf(stdin, "%d", &x)
		counter[x]++
	}
	// find min number
	minX := 1001
	for _, count := range counter {
		if count < minX {
			minX = count
		}
	}
	fmt.Println(minX)
}

package main

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

func main() {
	var n, m int
	counter := map[int]int{}
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d\n", &n, &m)
	for i := 0; i < m; i++ {
		var x int
		fmt.Fscanf(stdin, "%d", &x)
		counter[x]++
	}
	// find min number
	minX := 1001
	for col := 0; col < n; col++ {
		if counter[col] < minX {
			minX = counter[col]
		}
	}
	fmt.Println(minX)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[byte]int)

	for i := 0; i < colNum; i++ {
		tetris[byte(i + 1)] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		tetris[byte(j)]++
	}

	min := tetris[byte(1)]
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[byte]int)

	for i := 0; i < colNum; i++ {
		tetris[byte(i + 1)] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		_, ok := tetris[byte(j)]
		if ok {
			tetris[byte(j)]++
		} else {
			tetris[byte(j)] = 1
		}
	}

	min := 999
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	for _, v := range tetris {
		if v < min || v == 0 {
			fmt.Println(0)
			os.Exit(0)
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[byte]int)

	for i := 0; i < colNum; i++ {
		tetris[byte(i + 1)] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		tetris[byte(j)]++
	}

	min := math.MaxInt32
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[byte]int)

	for i := 0; i < colNum; i++ {
		tetris[byte(i + 1)] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		tetris[byte(j)]++
	}

	min := 999
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	colNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[byte]int)

	for i := 0; i < colNum; i++ {
		tetris[byte(i + 1)] = 0
	}

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		j, _ := strconv.Atoi(sqrs[i])
		_, ok := tetris[byte(j)]
		if ok {
			tetris[byte(j)]++
		} else {
			tetris[byte(j)] = 1
		}
	}

	min := 999
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _, _ := reader.ReadLine()

	cols := strings.Split(string(input), " ")
	//colsNum, _ := strconv.Atoi(cols[0])
	times, _ := strconv.Atoi(cols[1])

	tetris := make(map[string]int)

	n, _, _ := reader.ReadLine()

	sqrs := strings.Split(string(n), " ")
	for i := 0; i < times; i++ {
		_, ok := tetris[string(sqrs[i])]
		if ok {
			tetris[string(sqrs[i])]++
		} else {
			tetris[string(sqrs[i])] = 1
		}
	}

	min := 999
	for _, v := range tetris {
		if v < min {
			min = v
		}
	}
	fmt.Println(min)
}

package main

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

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

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

func main() {
    defer writer.Flush()

    var n, m int
    scanf("%d%d\n", &n, &m);
    var cnt [1005]int
    for i := 0; i < m; i++ {
        var a int
        scanf("%d", &a);
        cnt[a - 1] += 1
    }
    var ans = int(^uint(0) >> 1)
    for i := 0; i < n; i++ {
        ans = min(ans, cnt[i])
    }
    println(ans)
}


package main

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

type occ struct {
	num   int
	count int64
}

func minimize(num, m int) (int, int64) {
	count := int64(1)
	for num > 1 && num%m == 0 {
		num = num / m
		count *= int64(m)
	}
	return num, count
}

func readOcc(n, m int, r *bufio.Reader) []occ {
	ret := make([]occ, 0, n)
	for ; n > 0; n-- {
		var x int
		_, _ = fmt.Fscan(r, &x)
		num, count := minimize(x, m)
		if len(ret) > 0 && ret[len(ret)-1].num == num {
			ret[len(ret)-1].count += count
		} else {
			ret = append(ret, occ{num, count})
		}
	}
	return ret
}

func isEqual(a, b []occ) bool {
	if len(a) != len(b) {
		return false
	}
	for i, o := range a {
		if o != b[i] {
			return false
		}
	}
	return true
}

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

	var t int
	_, _ = fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n, m int
		_, _ = fmt.Fscan(r, &n, &m)
		a := readOcc(n, m, r)
		_, _ = fmt.Fscan(r, &n)
		b := readOcc(n, m, r)
		if len(a) != len(b) {
			fmt.Fprintln(w, "No")
			continue
		}
		if isEqual(a, b) {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}
}

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

package main

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

/*
2
5 3
2 2 3 1 6
7
2 2 1 1 1 1 6
5 3
2 2 3 1 6
5
2 2 1 3 6
---
YES
YES
*/

type seg struct {
	num, cnt int64
}

func mergeLastTwo(segs []seg) []seg {
	if len(segs) < 2 {
		return segs
	}

	top := segs[len(segs)-1]
	segs = segs[:len(segs)-1]

	for len(segs) > 0 && segs[len(segs)-1].num == top.num {
		top.cnt += segs[len(segs)-1].cnt
		segs = segs[:len(segs)-1]
	}

	segs = append(segs, top)

	return segs
}

func toSeg(num, m int64) seg {
	if num%m != 0 {
		return seg{num, 1}
	}

	k := num

	for k%m == 0 {
		k /= m
	}

	return seg{k, num / k}
}

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, m int64
	scanf("%d %d\n", &n, &m)

	a := make([]seg, 0)

	for i := int64(0); i < n; i++ {
		var num int64
		scanf("%d", &num)

		a = append(a, toSeg(num, m))
		a = mergeLastTwo(a)
	}
	scanf("\n")

	var k int
	scanf("%d\n", &k)

	b := make([]seg, 0)

	for i := 0; i < k; i++ {
		var num int64
		scanf("%d", &num)

		b = append(b, toSeg(num, m))
		b = mergeLastTwo(b)
	}
	scanf("\n")

	if len(a) != len(b) {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(a); i++ {
		if a[i].num != b[i].num || a[i].cnt != b[i].cnt {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	fmt.Fprintln(writer, "YES")
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

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

/*
2
5 3
2 2 3 1 6
7
2 2 1 1 1 1 6
5 3
2 2 3 1 6
5
2 2 1 3 6
---
YES
YES
*/

type seg struct {
	num, cnt int64
}

func mergeLastTwo(segs []seg, m int64) []seg {
	if len(segs) < 2 {
		return segs
	}

	top := segs[len(segs)-1]
	segs = segs[:len(segs)-1]

	for len(segs) > 0 {
		if segs[len(segs)-1].num != top.num {
			break
		}

		top.cnt += segs[len(segs)-1].cnt
		segs = segs[:len(segs)-1]
	}

	sm := top.cnt
	qtt := sm / m
	rem := sm % m

	if (qtt > 0 && rem == 0) || qtt == 0 {
		segs = append(segs, top)
	} else {
		segs = append(segs, seg{num: top.num, cnt: qtt * m})
		segs = append(segs, seg{num: top.num, cnt: rem})
	}

	return segs
}

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, m int64
	scanf("%d %d\n", &n, &m)

	a := make([]seg, 0)

	for i := int64(0); i < n; i++ {
		var num int64
		scanf("%d", &num)

		if num%m == 0 {
			x := num

			for x%m == 0 {
				x /= m
			}

			a = append(a, seg{x, num / x})
		} else {
			a = append(a, seg{num, 1})
		}

		a = mergeLastTwo(a, m)
	}
	scanf("\n")

	var k int
	scanf("%d\n", &k)

	b := make([]seg, 0)

	for i := 0; i < k; i++ {
		var num int64
		scanf("%d", &num)

		if num%m == 0 {
			x := num

			for x%m == 0 {
				x /= m
			}

			b = append(b, seg{x, num / x})
		} else {
			b = append(b, seg{num, 1})
		}

		b = mergeLastTwo(b, m)
	}
	scanf("\n")

	if len(a) != len(b) {
		fmt.Fprintln(writer, "NO")
		return
	}

	for i := 0; i < len(a); i++ {
		if a[i].num != b[i].num || a[i].cnt != b[i].cnt {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	fmt.Fprintln(writer, "YES")
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

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

type Stat struct {
	x int
	c int64
}

type Task struct {
	n, m, l int
	a, b []Stat
}

func ReadArray(reader io.Reader, n int, m int) []Stat {
	a := make([]Stat, 0, n)
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		c := int64(1)
		for ak % m == 0 {
			ak /= m
			c *= int64(m)
		}
		if (len(a) > 0 && a[len(a) - 1].x == ak) {
			a[len(a) - 1].c += c
		} else {
			a = append(a, Stat{x: ak, c: c})
		}
	}
	return a
}

func Solve(task Task) string {
	a := task.a
	b := task.b

	ok := true
	for len(b) > 0 && len(a) > 0 && ok {
		lastA := &a[len(a) - 1]
		lastB := &b[len(b) - 1]
		ok = lastA.x == lastB.x && lastA.c >= lastB.c
		lastA.c -= lastB.c
		b = b[:len(b) - 1]
		if (lastA.c == 0) {
			a = a[:len(a) - 1]
		}
	}

	if ok && len(a) == 0 && len(b) == 0 {
		return "Yes"
	} else {
		return "No"
	}
}

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

	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	tasks := make(chan Task)
	go func(out chan<- Task){
		for t := 0; t < testCaseCount; t++ {
			var task Task
			fmt.Fscan(reader, &task.n, &task.m)
			task.a = ReadArray(reader, task.n, task.m)
			fmt.Fscan(reader, &task.l)
			task.b = ReadArray(reader, task.l, task.m)
			out <- task
		}
	}(tasks)

	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	for t := 0; t < testCaseCount; t++ {
		task := <-tasks
		ans := Solve(task)
		fmt.Fprintln(writer, ans)
	}
}

package main

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

type Stat struct {
	x int
	c int64
}

func ReadArray(reader io.Reader, n int, m int) []Stat {
	a := make([]Stat, 0, n)
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		c := int64(1)
		for ak % m == 0 {
			ak /= m
			c *= int64(m)
		}
		if (len(a) > 0 && a[len(a) - 1].x == ak) {
			a[len(a) - 1].c += c
		} else {
			a = append(a, Stat{x: ak, c: c})
		}
	}
	return a
}

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var (
		n int
		m int
		l int
	)
	fmt.Fscan(reader, &n, &m)
	a := ReadArray(reader, n, m)
	fmt.Fscan(reader, &l)
	b := ReadArray(reader, l, m)

	ok := true
	for len(b) > 0 && len(a) > 0 && ok {
		lastA := &a[len(a) - 1]
		lastB := &b[len(b) - 1]
		ok = lastA.x == lastB.x && lastA.c >= lastB.c
		lastA.c -= lastB.c
		b = b[:len(b) - 1]
		if (lastA.c == 0) {
			a = a[:len(a) - 1]
		}
	}

	if ok && len(a) == 0 && len(b) == 0 {
		fmt.Fprintln(writer, "Yes")
	} else {
		fmt.Fprintln(writer, "No")
	}
}

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

	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

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

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

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

		aa := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}
		var k int
		fmt.Fscan(in, &k)
		bb := make([]int64, k)
		for i := 0; i < k; i++ {
			fmt.Fscan(in, &bb[i])
		}

		g := func(n int64) int64 {
			for n%m == 0 {
				n /= m
			}
			return n
		}
		f := true
		var i, j int
		var t1, t2 int64
		for i < n && j < k {
			t1, t2 = 0, 0
			z := g(aa[i])
			for i < n && z == g(aa[i]) {
				t1 += aa[i] / z
				i++
			}
			for j < k && z == g(bb[j]) {
				t2 += bb[j] / z
				j++
			}

			if t1 != t2 {
				f = false
				break
			}
		}

		if f && i == n && j == k {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}
}

package main

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

type pair struct {
	v int
	c int64
}

func getS(a []int, m int) []pair {
	ans := make([]pair, 0, len(a))

	for _, v := range a {
		c := int64(1)
		for v%m == 0 {
			v /= m
			c *= int64(m)
		}

		if len(ans) != 0 && ans[len(ans)-1].v == v {
			ans[len(ans)-1].c += c
		} else {
			ans = append(ans, pair{v, c})
		}
	}
	return ans
}

func solve(a, b []int, m int) bool {
	sa := getS(a, m)
	sb := getS(b, m)
	if len(sa) != len(sb) {
		return false
	}
	for i := 0; i < len(sa); i++ {
		v1, v2 := sa[i], sb[i]
		if v1 != v2 {
			return false
		}
	}
	return true
}

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

	var t int
	var n int
	var k int
	var m int
	a := make([]int, 1e5)
	b := make([]int, 1e5)
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		Fscan(in, &k)
		for i := 0; i < k; i++ {
			Fscan(in, &b[i])
		}

		ans := solve(a[:n], b[:k], m)
		if ans {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	run(os.Stdin, os.Stdout)
	// a := []int{1, 2, 2, 4, 2}
	// a = []int{1, 2, 2, 8, 2, 2}
	// a = []int{1, 16}
	// a = []int{3, 9, 6, 3, 12, 12, 36, 12}
	// a = []int{9, 3, 2, 2, 2, 3, 4, 12, 4, 12, 4, 12, 4, 12, 4, 4}
	// a = []int{1, 4, 4, 2}
	// a = []int{1, 1000000000, 1000000000, 1000000000}
	// ans := getS(a, 1000000000)
	// fmt.Println(ans)
}

package main

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

type occ struct {
	num   int
	count int64
}

func minimize(num, m int) (int, int64) {
	count := int64(1)
	for num > 1 && num%m == 0 {
		num = num / m
		count *= int64(m)
	}
	return num, count
}

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

	var t int
	_, _ = fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n, m int
		_, _ = fmt.Fscan(r, &n, &m)
		a := make([]occ, 0, n)
		for ; n > 0; n-- {
			var x int
			_, _ = fmt.Fscan(r, &x)
			num, count := minimize(x, m)
			if len(a) > 0 && a[len(a)-1].num == num {
				a[len(a)-1].count += count
			} else {
				a = append(a, occ{num, count})
			}
		}
		_, _ = fmt.Fscan(r, &n)
		b := make([]occ, 0, n)
		for ; n > 0; n-- {
			var x int
			_, _ = fmt.Fscan(r, &x)
			num, count := minimize(x, m)
			if len(b) > 0 && b[len(b)-1].num == num {
				b[len(b)-1].count += count
			} else {
				b = append(b, occ{num, count})
			}
		}
		if len(a) != len(b) {
			fmt.Fprintln(w, "No")
			continue
		}
		isEqual := true
		for i, o := range a {
			if o != b[i] {
				isEqual = false
				break
			}
		}
		if isEqual {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}
}

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

package main

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

type Stat struct {
	x, c int
}

func ReadArray(reader io.Reader, n int, m int) []Stat {
	a := make([]Stat, 0, n)
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		c := 1
		for ak % m == 0 {
			ak /= m
			c *= m
		}
		if (len(a) > 0 && a[len(a) - 1].x == ak) {
			a[len(a) - 1].c += c
		} else {
			a = append(a, Stat{x: ak, c: c})
		}
	}
	return a
}

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var (
		n int
		m int
		l int
	)
	fmt.Fscan(reader, &n, &m)
	a := ReadArray(reader, n, m)
	fmt.Fscan(reader, &l)
	b := ReadArray(reader, l, m)

	ok := true
	for len(b) > 0 && ok {
		lastA := &a[len(a) - 1]
		lastB := &b[len(b) - 1]
		ok = lastA.x == lastB.x && lastA.c >= lastB.c
		lastA.c -= lastB.c
		b = b[:len(b) - 1]
		if (lastA.c == 0) {
			a = a[:len(a) - 1]
		}
	}

	if ok && len(b) == 0 && len(a) == 0 {
		fmt.Fprintln(writer, "Yes")
	} else {
		fmt.Fprintln(writer, "No")
	}
}

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

	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

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

type Stat struct {
	x, c int
}

func ReadArray(reader io.Reader, n int, m int) []Stat {
	a := make([]Stat, 0, n)
	for k := 0; k < n; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		c := 1
		for ak % m == 0 {
			ak /= m
			c *= m
		}
		if (len(a) > 0 && a[len(a) - 1].x == ak) {
			a[len(a) - 1].c += c
		} else {
			a = append(a, Stat{x: ak, c: c})
		}
	}
	return a
}

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var (
		n int
		m int
		l int
	)
	fmt.Fscan(reader, &n, &m)
	a := ReadArray(reader, n, m)
	fmt.Fscan(reader, &l)
	b := ReadArray(reader, l, m)

	ok := true
	for len(b) > 0 && ok {
		lastA := a[len(a) - 1]
		lastB := b[len(b) - 1]
		ok = lastA.x == lastB.x && lastA.c >= lastB.c
		lastA.c -= lastB.c
		b = b[:len(b) - 1]
		if (lastA.c == 0) {
			a = a[:len(a) - 1]
		}
	}

	if ok && len(b) == 0 && len(a) == 0 {
		fmt.Fprintln(writer, "Yes")
	} else {
		fmt.Fprintln(writer, "No")
	}
}

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

	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

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

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

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

		aa := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}
		var k int
		fmt.Fscan(in, &k)
		bb := make([]int64, k)
		for i := 0; i < k; i++ {
			fmt.Fscan(in, &bb[i])
		}

		p1, p2 := 0, 0
		s1, s2 := []int64{}, []int64{}
		t1, t2 := int64(0), int64(0)
		f := true
		var m1 int64
		canMerge := func(a, b []int64) bool {
			if len(a) == 0 || len(b) == 0 {
				return false
			}

			g := make(map[int64]bool)
			for m1 > 0 {
				g[m1] = true
				m1 /= m
			}

			for _, v := range a {
				if !g[v] {
					return false
				}
			}

			for _, v := range b {
				if !g[v] {
					return false
				}
			}
			return true
		}

		for p1 < n && p2 < k {
			if t1 == 0 || t1 < t2 {
				s1 = append(s1, aa[p1])
				t1 += aa[p1]
				if aa[p1] > m1 {
					m1 = aa[p1]
				}
				p1++
			} else {
				s2 = append(s2, bb[p2])
				t2 += bb[p2]
				if bb[p2] > m1 {
					m1 = bb[p2]
				}
				p2++
			}

			if t1 == t2 {
				if !canMerge(s1, s2) {
					f = false
					break
				}
				s1, s2 = []int64{}, []int64{}
				t1, t2 = 0, 0
				m1 = 0
			}
		}

		if f && p1 < n {
			s1 = append(s1, aa[p1:]...)
		}
		if f && p2 < k {
			s2 = append(s2, bb[p2:]...)
		}

		if f && len(s1) > 0 && len(s2) > 0 {
			if !canMerge(s1, s2) {
				f = false
			}
			s1, s2 = []int64{}, []int64{}
		}

		if f && len(s1) == 0 && len(s2) == 0 {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}
}

package main

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

type pair struct{ v, c int }

func getS(a []int, m int) []pair {
	ans := make([]pair, 0, len(a))

	for _, v := range a {
		c := 1
		for v%m == 0 {
			v /= m
			c *= m
		}

		if len(ans) != 0 && ans[len(ans)-1].v == v {
			ans[len(ans)-1].c += c
		} else {
			ans = append(ans, pair{v, c})
		}
	}
	return ans
}

func solve(a, b []int, m int) bool {
	sa := getS(a, m)
	sb := getS(b, m)
	if len(sa) != len(sb) {
		return false
	}
	for i := 0; i < len(sa); i++ {
		v1, v2 := sa[i], sb[i]
		if v1 != v2 {
			return false
		}
	}
	return true
}

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

	var t int
	var n int
	var k int
	var m int
	a := make([]int, 1e5)
	b := make([]int, 1e5)
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		Fscan(in, &k)
		for i := 0; i < k; i++ {
			Fscan(in, &b[i])
		}

		ans := solve(a[:n], b[:k], m)
		if ans {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	run(os.Stdin, os.Stdout)
	// a := []int{1, 2, 2, 4, 2}
	// a = []int{1, 2, 2, 8, 2, 2}
	// a = []int{1, 16}
	// a = []int{3, 9, 6, 3, 12, 12, 36, 12}
	// a = []int{9, 3, 2, 2, 2, 3, 4, 12, 4, 12, 4, 12, 4, 12, 4, 4}
	// a = []int{1, 4, 4, 2}
	// a = []int{1, 1000000000, 1000000000, 1000000000}
	// ans := getS(a, 1000000000)
	// fmt.Println(ans)
}

package main

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

type pair struct{ v, c int }

func getS(a []int, m int) []pair {
	ans := make([]pair, 0, len(a))
	var dfs func(n *int) int
	dfs = func(n *int) int {
		if *n%m != 0 {
			return 1
		}
		*n /= m
		return m * dfs(n)
	}

	for _, v := range a {
		if v%m != 0 {
			if len(ans) != 0 && ans[len(ans)-1].v == v {
				ans[len(ans)-1].c += 1
			} else {
				ans = append(ans, pair{v, 1})
			}
		} else {
			c := dfs(&v)

			if len(ans) != 0 && ans[len(ans)-1].v == v {
				ans[len(ans)-1].c += c
			} else {
				ans = append(ans, pair{v, c})
			}
		}
	}
	return ans
}

func solve(a, b []int, m int) bool {
	sa := getS(a, m)
	sb := getS(b, m)
	if len(sa) != len(sb) {
		return false
	}
	for i := 0; i < len(sa); i++ {
		v1, v2 := sa[i], sb[i]
		if v1 != v2 {
			return false
		}
	}
	return true
}

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

	var t int
	var n int
	var k int
	var m int
	a := make([]int, 1e5)
	b := make([]int, 1e5)
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		for i := 0; i < n; i++ {
			Fscan(in, &a[i])
		}
		Fscan(in, &k)
		for i := 0; i < k; i++ {
			Fscan(in, &b[i])
		}

		ans := solve(a[:n], b[:k], m)
		if ans {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func main() {
	run(os.Stdin, os.Stdout)
	// fmt.Println("go")
	// a := []int{1, 2, 2, 4, 2}
	// a = []int{1, 2, 2, 8, 2, 2}
	// a = []int{1, 16}
	// a = []int{3, 9, 6, 3, 12, 12, 36, 12}
	// a = []int{9, 3, 2, 2, 2, 3, 4, 12, 4, 12, 4, 12, 4, 12, 4, 4}
	// a = []int{1, 4, 4, 2}
	// ans := getS(a, 2)
	// fmt.Println(ans)
}

package main

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

type occ struct {
	num, count int
}

func minimize(num, m int) (int, int) {
	count := 1
	for num > 1 && num%m == 0 {
		num = num / m
		count *= m
	}
	return num, count
}

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

	var t int
	_, _ = fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n, m int
		_, _ = fmt.Fscan(r, &n, &m)
		a := make([]occ, 0, n)
		for ; n > 0; n-- {
			var x int
			_, _ = fmt.Fscan(r, &x)
			num, count := minimize(x, m)
			if len(a) > 0 && a[len(a)-1].num == num {
				a[len(a)-1].count += count
			} else {
				a = append(a, occ{num, count})
			}
		}
		_, _ = fmt.Fscan(r, &n)
		b := make([]occ, 0, n)
		for ; n > 0; n-- {
			var x int
			_, _ = fmt.Fscan(r, &x)
			num, count := minimize(x, m)
			if len(b) > 0 && b[len(b)-1].num == num {
				b[len(b)-1].count += count
			} else {
				b = append(b, occ{num, count})
			}
		}
		if len(a) != len(b) {
			fmt.Fprintln(w, "No")
			continue
		}
		isEqual := true
		for i, o := range a {
			if o != b[i] {
				isEqual = false
				break
			}
		}
		if isEqual {
			fmt.Fprintln(w, "Yes")
		} else {
			fmt.Fprintln(w, "No")
		}
	}
}

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


package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

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

func lowerBound(arr []int, t int) int {
	lo := 0
	hi := len(arr)
	for lo < hi {
		mid := lo + (hi-lo)/2
		if arr[mid] >= t {
			hi = mid
		} else {
			lo = mid + 1
		}
	}
	return hi
}

const (
	INIT = -1
	INF  = int(1e9)
)

var (
	r      = bufio.NewReader(os.Stdin)
	w      = bufio.NewWriter(os.Stdout)
	exists = struct{}{} // for use with map[...]struct{}

	n int
	a []int64
)

func output() {
	for i := 0; i < n; i++ {
		fmt.Fprintf(w, "%d ", a[i])
	}
	fmt.Fprintln(w)
}
func solve() bool {
	check(len(a) == n+2)
	sort.Slice(a, func(i, j int) bool {
		return a[i] < a[j]
	})

	var sum int64
	for i := 0; i < len(a); i++ {
		sum += a[i]
	}

	if sum-a[n+1] == 2*a[n] {
		// fmt.Printf("I %+v\n", a)
		output()
		return true
	}

	for i := 0; i < n+1; i++ {
		x := a[i]
		if sum-x == 2*a[n+1] {
			a[i], a[n+1] = a[n+1], a[i]
			a[i], a[n] = a[n], a[i]

			// fmt.Printf("II %+v\n", a)
			output()
			return true
		}
	}
	return false
}

func main() {
	defer w.Flush()

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

	for ; tc > 0; tc-- {
		fmt.Fscan(r, &n)
		a = make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(r, &a[i])
		}

		if !solve() {
			fmt.Fprintln(w, INIT)
		}
	}
}

// link: https://codeforces.com/problemset/problem/1512/D
// b(n+1) must be biggest or second biggest number

package main

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

func logic(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

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

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

		bArr := make([]uint64, n+2)

		var biggestValIndex uint64
		var biggestVal uint64
		var secondBiggestValIndex uint64
		var secondBiggestVal uint64
		var sum uint64
		for j := 0; j < n+2; j++ {
			var val uint64
			fmt.Fscan(in, &val)

			bArr[j] = val
			sum += val

			if val > biggestVal {
				secondBiggestValIndex = biggestValIndex
				secondBiggestVal = biggestVal

				biggestValIndex = uint64(j)
				biggestVal = val
			} else if val > secondBiggestVal {
				secondBiggestValIndex = uint64(j)
				secondBiggestVal = val
			}
		}

		// let b(n+2) = biggestVal, b(n+1) = secondBiggestVal
		if sum-biggestVal-secondBiggestVal == secondBiggestVal {
			for j := 0; j < n+2; j++ {
				if uint64(j) == biggestValIndex || uint64(j) == secondBiggestValIndex {
					continue
				}

				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
			continue
		}

		// let b(n+1) = biggestVal
		sumOfAnPlusX := sum - biggestVal
		x := -1

		for j := 0; j < n+2; j++ {
			if uint64(j) == biggestValIndex {
				continue
			}

			if sumOfAnPlusX-bArr[j] == biggestVal {
				x = j
				break
			}
		}

		if x == -1 {
			fmt.Fprintln(out, "-1")
		} else {
			for j := 0; j < n+2; j++ {
				if uint64(j) == biggestValIndex || j == x {
					continue
				}

				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
		}
	}
}

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

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int64]int), make([]int64, n + 2)

		var sum int64
		for i, _ := range nums {
			Fscan(in, &nums[i])
			sum += nums[i]
			mp[nums[i]]++
		}

		pos, s := -1, -1
		if sum & 0x1 == 0 {
			for i, val := range nums {
				if val & 0x1 == 0 {
					if (sum - val) / 2 != val || ((sum - val) / 2 == val && mp[val] > 1) {
						if mp[(sum - val) >> 1] != 0 {
							pos = i
							break
						}
					}
				}
			}

		} else {
			for i, val := range nums {
				if val & 0x1 == 1 {
					if (sum - val) / 2 != val || ((sum - val) / 2 == val && mp[val] > 1) {
						if mp[(sum - val) / 2] > 0 {
							pos = i
							break
						}
					}
				}
			}
		}

		if pos == -1 {
			Fprintln(out, -1)
		} else {
			for i, val := range nums {
				if i != pos && val == (sum - nums[pos]) / 2 {
					s = i
				}
			}
			for i, val := range nums {
				if i != s && i != pos {
					Fprint(out, val, " ")
				}
			}
			Fprintln(out)
		}
	}
}

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

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

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

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

package main

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

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

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		var sum int64
		sum = 0

		for i := 0; i < n; i++ {
			sum += a[i]
		}

		if sum == a[n] {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, a[i], " ")
			}
			fmt.Fprintln(out)
		} else {
			sum += a[n]
			pos := -1
			for i := 0; i <= n; i++ {
				if sum-a[i] == a[n+1] {
					pos = i
					break
				}
			}
			if pos == -1 {
				fmt.Fprintln(out, -1)
			} else {
				for i := 0; i < n+1; i++ {
					if pos != i {
						fmt.Fprint(out, a[i], " ")
					}
				}
				fmt.Fprintln(out)
			}
		}

	}

	var T int
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		fmt.Fscan(in, &n)
		v := []int{}
		freq := map[int]int{}
		var sum int64
		for i := 0; i<n+2 ; i++ {
			var x int
			fmt.Fscan(in, &x)
			v = append(v, x) //*
			freq[x]++
			sum += int64(x)
		}
		sort.Ints(v)
		ok := false
		for i, x := range v {
			rem := sum - int64(x)
			if rem % 2 == 1 {
				continue
			}
			rem /= 2
			need := 1
			if int(rem) == x {
				need++
			}
			if rem <= int64(v[n+1]) && freq[int(rem)] >= need {
				ok = true
				v[i] = -1
				sum = rem
				break
			}
		}
		if !ok {
			fmt.Println(-1)
			continue
		}
		for _, x := range v {
			if x != int(sum) && x!=-1 {
				fmt.Printf("%d ", x)
			}else if x == int(sum) {
				sum = -1
			}
		}
		fmt.Println("")
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)

		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				skip_high := true
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high {
						if i == skip {
							continue
						} else if skip_high {
							skip_high = false
							continue
						}
					}
					write(f, b[i], " ")
				}
				write(f, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n + 2)
		var sum int64 = 0
		for i := 0; i < n + 2; i++ {
			fmt.Fscan(in, &arr[i])
			sum = sum + int64(arr[i])
		}
		sort.Ints(arr)
		sum -= int64(arr[n + 1])
		var done = false
		for i := 0; i <= n; i++ {
			if sum - int64(arr[i]) == int64(arr[n + 1]) {
				for j := 0; j <= n; j++ {
					if i == j {
						continue
					}
					fmt.Fprint(out, arr[j], " ")
				}
				fmt.Fprintln(out, "")
				done = true
				break
			}
		}
		if done {
			t--
			continue
		}
		if sum - int64(arr[n]) == int64(arr[n]) {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, arr[i], " ")
			}
			fmt.Fprintln(out, "")
			done = true
		}
		if done {
			t--
			continue
		}
		fmt.Fprintln(out, -1)
		t--
	}
	out.Flush()

}

package main

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

/*
1
3
2 3 7 12 2
---

sumB == 2*sumA + x

sumB-x == 2*sumA

sumA = (sunB-x)/2

if sumB-x-sumA == sumA and sumA in b:
	yes
else:
	no

2 2 3 7 12
=======
1
3
0 0 0 0 0
---
0 0 0
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		sumB := int64(0)
		b := make([]int64, n+2)
		numToIdx := make(map[int64][]int)

		for i := range b {
			scanf("%d", &b[i])

			sumB += b[i]
			numToIdx[b[i]] = append(numToIdx[b[i]], i)
		}
		scanf("\n")

		found := false

	outer:
		for i, x := range b {
			if (sumB-x)%2 == 0 {
				sumA := (sumB - x) / 2
				indices := numToIdx[sumA]
				for _, k := range indices {
					if sumB-x-sumA == sumA && k != i {
						for j, num := range b {
							if j != i && j != k {
								fmt.Fprintf(writer, "%d ", num)
							}
						}
						fmt.Fprintln(writer)
						found = true
						break outer
					}
				}
			}
		}

		if !found {
			fmt.Fprintln(writer, -1)
		}
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int64) int64 {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

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

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

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

}

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

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

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		ARRAY := make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		sort.Slice(ARRAY, func(i, j int) bool {
			return ARRAY[i] < ARRAY[j]
		})
		var SUM int64
		for i := 0; i < n; i++ {
			SUM = SUM + ARRAY[i]
		}
		if ARRAY[n] == SUM {
			for i := 0; i < n; i++ {
				fmt.Println(ARRAY[i])
			}
		} else {
			q := SUM + ARRAY[n] - ARRAY[n+1]
			if q <= 0 {
				fmt.Println(-1)
			} else {
				w := -1
				for i := 0; i < n+1; i++ {
					if ARRAY[i] == q {
						w = i
					}
				}
				if w == -1 {
					fmt.Println(-1)
				} else {
					for i := 0; i < n+1; i++ {
						if i != w {
							fmt.Println(ARRAY[i])
						}
					}
				}
			}
		}

	}
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}
func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}
func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func solve(N int, arr []int) []int {
	ans := []int{}

	sort.Ints(arr)
	sum := int64(0)
	for i := 0; i < N+2; i++ {
		sum += int64(arr[i])
	}

	for i := 0; i < N+1; i++ {
		sumA := sum - int64(arr[N+1]+arr[i])
		if sumA == int64(arr[N+1]) {
			for j := 0; j < N+1; j++ {
				if j == i {
					continue
				}
				ans = append(ans, arr[j])
			}
			return ans
		}
	}
	sumA := sum - int64(arr[N]+arr[N+1])
	if sumA == int64(arr[N]) {
		for j := 0; j < N; j++ {
			ans = append(ans, arr[j])
		}
		return ans
	}
	return nil
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.nextInt()
		arr := sc.nextInts(N + 2)

		ans := solve(N, arr)
		if ans == nil {
			fmt.Fprintln(wr, "-1")
		} else {
			for i := 0; i < N; i++ {
				fmt.Fprint(wr, ans[i], " ")
			}
			fmt.Fprintln(wr)
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"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) {
		var n int
		Fscan(in, &n)
		a := make([]int64, n+2)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		sum := int64(0)
		for _, v := range a[:n] {
			sum += v
		}
		if sum == a[n] {
			for _, v := range a[:n] {
				Fprint(out, v, " ")
			}
			Fprintln(out)
			return
		}
		sum += a[n]-a[n+1]
		if sum<=0 {
			Fprintln(out, -1)
			return
		}
		b := a[:n+1]
		for i, v := range b {
			if v == sum {
				b = append(b[:i], b[i+1:]...)
				for _, v := range b {
					Fprint(out, v, " ")
				}
				Fprintln(out)
				return
			}
		}
		Fprintln(out, -1)
	}

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

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

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

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
		}
		sort.Ints(b)
		ps := 0
		for i := 0; i < n; i++ {
			ps += b[i]
		}
		if ps == b[n] || ps == b[n+1] {
			for i := 0; i < n; i++ {
				write(f, b[i])
				if i == n-1 {
					write(f, "\n")
				} else {
					write(f, " ")
				}
			}
		} else {
			rem := ps - (b[n+1] - b[n])
			ok := false
			skip := -1
			for i := 0; i < n; i++ {
				if b[i] == rem {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n; i++ {
					if i == skip {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, b[n], "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		b := make([]int, n + 2)

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

		r, ar := solve(b, n)

		if !r {
			fmt.Println("-1")
		} else {
			for j := 0; j < len(ar); j++ {
				fmt.Print(ar[j])
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func solve(b []int, n int) (bool, []int) {
	mp := make(map[int64][]int)

	var s int64

	for i :=0 ; i < len(b); i++ {
		if len(mp[int64(b[i])]) < 2 {
			mp[int64(b[i])] = append(mp[int64(b[i])], i)
		}

		s += int64(b[i])
	}

	var a []int

	for i := 0; i < len(b); i++ {
		rest := s - int64(b[i])

		if rest % 2 == 1 {
			continue
		}

		r := rest/2

		v, ok := mp[r]

		var idx int = -1

		if ok {

			for k := 0; k < len(v); k++ {
				if v[k] != i {
					idx = v[k]
				}
			}
		}

		if idx == -1 {
			continue
		}

		if ok {
			for j := 0; j < len(b); j++ {
				if j == i || j == idx {
					continue
				}
				a = append(a, b[j])
			}
			return true, a
		}
	}

	return false, []int{}
}

// link: https://codeforces.com/problemset/problem/1512/D
// b(n+1) must be biggest or second biggest number

package main

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

func logic(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

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

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

		bArr := make([]uint64, n+2)

		for j := 0; j < n+2; j++ {
			var val uint64
			fmt.Fscan(in, &val)

			bArr[j] = val
		}

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

		var sum uint64
		for j := 0; j < n; j++ {
			sum += bArr[j]
		}

		if sum == bArr[n] {
			for j := 0; j < n; j++ {
				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
			continue
		}

		sum += bArr[n]

		var found bool
		for j := 0; j < n+1; j++ {
			if sum-bArr[j] == bArr[n+1] {
				bArr[j] = 0
				found = true
				break
			}
		}

		if found {
			for j := 0; j < n+1; j++ {
				if bArr[j] == 0 {
					continue
				}
				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out, "-1")
		}
	}
}

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

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		if t == 426 {
			fmt.Println(b)
		}
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				skip_high := true
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high {
						if i == skip {
							continue
						} else if skip_high {
							skip_high = false
							continue
						}
					}
					write(f, b[i], " ")
				}
				write(f, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		if t == 426 {
			fmt.Println(b)
		}
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)

		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		if t == 490 {
			fmt.Println(b)
		}
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high || b[i] == shigh {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, shigh, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem && b[i] != shigh && b[i] != high {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high || b[i] == shigh {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, shigh, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			skip_high := true
			ship_shigh := true
			for i := 0; i < n+2; i++ {
				if skip_high {
					if b[i] == high {
						skip_high = false
						continue
					}
				}
				if ship_shigh {
					if b[i] == shigh {
						ship_shigh = false
						continue
					}
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high || b[i] == shigh {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, shigh, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		ps := 0

		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
			ps += b[i]
		}
		// sort.Ints(b)
		ps -= (high + shigh)
		if ps == high || ps == shigh {
			count := 2
			for i := 0; i < n+2; i++ {
				if (b[i] == high || b[i] == shigh) && count > 0 {
					count--
					continue
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high || b[i] == shigh {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, shigh, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		b := make([]int, n+2)
		high := 0
		shigh := 0
		for i := 0; i < n+2; i++ {
			fmt.Fscan(reader, &b[i])
			if b[i] <= high && b[i] > shigh {
				shigh = b[i]
			} else if b[i] > high {
				shigh = high
				high = b[i]
			}
		}
		// sort.Ints(b)
		ps := 0
		for i := 0; i < n+2; i++ {
			if b[i] != high && b[i] != shigh {
				ps += b[i]
			}
		}
		if ps == high || ps == shigh {
			for i := 0; i < n+2; i++ {
				if b[i] == high || b[i] == shigh {
					continue
				}
				write(f, b[i], " ")
			}
			write(f, "\n")
		} else {
			rem := ps - (high - shigh)
			ok := false
			skip := -1
			for i := 0; i < n+2; i++ {
				if b[i] == rem {
					ok = true
					skip = i
					break
				}
			}
			if ok {
				for i := 0; i < n+2; i++ {
					if i == skip || b[i] == high || b[i] == shigh {
						continue
					}
					write(f, b[i], " ")
				}
				write(f, shigh, "\n")
			} else {
				write(f, "-1\n")
			}
		}
	}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		b := make([]int, n + 2)

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

		r, ar := solve(b, n)

		if !r {
			fmt.Println("-1")
		} else {
			for j := 0; j < len(ar); j++ {
				fmt.Print(ar[j])
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func solve(b []int, n int) (bool, []int) {
	mp := make(map[int][]int)

	var s int64

	for i :=0 ; i < len(b); i++ {
		if len(mp[b[i]]) < 5 {
			mp[b[i]] = append(mp[b[i]], i)
		}

		s += int64(b[i])
	}

	var a []int

	for i := 0; i < len(b); i++ {
		rest := s - int64(b[i])

		if rest % 2 == 1 {
			continue
		}

		r := rest/2

		v, ok := mp[int(r)]

		var idx int = -1

		if ok {

			for k := 0; k < len(v); k++ {
				if v[k] != i {
					idx = v[k]
				}
			}
		}

		if idx == -1 {
			continue
		}

		if ok {
			for j := 0; j < len(b); j++ {
				if j == i || j == idx {
					continue
				}
				a = append(a, b[j])
			}
			return true, a
		}
	}

	return false, []int{}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		b := make([]int, n + 2)

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

		r, ar := solve(b, n)

		if !r {
			fmt.Println("-1")
		} else {
			for j := 0; j < len(ar); j++ {
				fmt.Print(ar[j])
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func solve(b []int, n int) (bool, []int) {
	mp := make(map[int][]int)

	var s int64

	for i :=0 ; i < len(b); i++ {
		if len(mp[b[i]]) < 2 {
			mp[b[i]] = append(mp[b[i]], i)
		}

		s += int64(b[i])
	}

	var a []int

	for i := 0; i < len(b); i++ {
		rest := s - int64(b[i])

		if rest % 2 == 1 {
			continue
		}

		r := rest/2

		v, ok := mp[int(r)]

		var idx int = -1

		if ok {

			for k := 0; k < len(v); k++ {
				if v[k] != i {
					idx = v[k]
				}
			}
		}

		if idx == -1 {
			continue
		}

		if ok {
			for j := 0; j < len(b); j++ {
				if j == i || j == idx {
					continue
				}
				a = append(a, b[j])
			}
			return true, a
		}
	}

	return false, []int{}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		b := make([]int, n + 2)

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

		r, ar := solve(b, n)

		if !r {
			fmt.Println("-1")
		} else {
			for j := 0; j < len(ar); j++ {
				fmt.Print(ar[j])
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func solve(b []int, n int) (bool, []int) {
	mp := make(map[int]int)

	var s int64

	for i :=0 ; i < len(b); i++ {
		mp[b[i]] = i

		s += int64(b[i])
	}

	var a []int

	for i := 0; i < len(b); i++ {
		rest := s - int64(b[i])

		if rest % 2 == 1 {
			continue
		}

		r := rest/2

		v, ok := mp[int(r)]

		if ok {
			if v == i {
				continue
			}
		}

		if ok {
			for j := 0; j < len(b); j++ {
				if j == i || j == v {
					continue
				}
				a = append(a, b[j])
			}
			return true, a
		}
	}

	return false, []int{}
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {
		var n int

		fmt.Fscan(r, &n)

		b := make([]int, n + 2)

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

		r, ar := solve(b, n)

		if !r {
			fmt.Println("-1")
		} else {
			for j := 0; j < len(ar); j++ {
				fmt.Print(ar[j])
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func solve(b []int, n int) (bool, []int) {
	mp := make(map[int]int)

	var s int64

	for i :=0 ; i < len(b); i++ {
		mp[b[i]] = i

		s+= int64(b[i])
	}

	var a []int

	for i := 0; i < len(b); i++ {
		rest := s - int64(b[i])

		if rest % 2 == 1 {
			continue
		}

		r := rest/2

		v, ok := mp[int(r)]

		if ok {
			for j := 0; j < len(b); j++ {
				if j == i || j == v {
					continue
				}
				a = append(a, b[j])
			}
			return true, a
		}
	}

	return false, []int{}
}

// link: https://codeforces.com/problemset/problem/1512/D
// b(n+1) must be biggest or second biggest number

package main

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

func logic(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

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

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

		bArr := make([]int, n+2)

		var biggestValIndex int
		var biggestVal int
		var secondBiggestValIndex int
		var secondBiggestVal int
		var sum int
		for j := 0; j < n+2; j++ {
			var val int
			fmt.Fscan(in, &val)

			bArr[j] = val
			sum += val

			if val > biggestVal {
				secondBiggestValIndex = biggestValIndex
				secondBiggestVal = biggestVal

				biggestValIndex = j
				biggestVal = val
			} else if val > secondBiggestVal {
				secondBiggestValIndex = j
				secondBiggestVal = val
			}
		}

		// let b(n+2) = biggestVal, b(n+1) = secondBiggestVal
		if sum-biggestVal-secondBiggestVal == secondBiggestVal {
			for j := 0; j < n+2; j++ {
				if j == biggestValIndex || j == secondBiggestValIndex {
					continue
				}

				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
			continue
		}

		// let b(n+1) = biggestVal
		sumOfAnPlusX := sum - biggestVal
		x := -1

		for j := 0; j < n+2; j++ {
			if j == biggestValIndex {
				continue
			}

			if sumOfAnPlusX-bArr[j] == biggestVal {
				x = j
				break
			}
		}

		if x == -1 {
			fmt.Fprintln(out, "-1")
		} else {
			for j := 0; j < n+2; j++ {
				if j == biggestValIndex || j == x {
					continue
				}

				fmt.Fprintf(out, "%d ", bArr[j])
			}
			fmt.Fprintln(out)
		}
	}
}

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

package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

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

func lowerBound(arr []int, t int) int {
	lo := 0
	hi := len(arr)
	for lo < hi {
		mid := lo + (hi-lo)/2
		if arr[mid] >= t {
			hi = mid
		} else {
			lo = mid + 1
		}
	}
	return hi
}

const (
	INIT = -1
	INF  = int(1e9)
)

var (
	r      = bufio.NewReader(os.Stdin)
	w      = bufio.NewWriter(os.Stdout)
	exists = struct{}{} // for use with map[...]struct{}

	n int
	a []int64
)

func solve() bool {
	var sum int64
	has := make(map[int64]int)
	for i := 0; i < n+2; i++ {
		sum += a[i]
		has[a[i]] = i
	}
	// fmt.Printf("has %+v\n", has)

	for i := 0; i < n+2; i++ {
		x := a[i]
		total := sum - x
		if (total % 2) != 0 {
			continue
		}
		half := total / 2

		if j, ok := has[half]; ok {
			if j == i {
				continue
			}

			a[j], a[n] = a[n], a[j]
			a[i], a[n+1] = a[n+1], a[i]

			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", a[i])
			}
			fmt.Fprintln(w)
			return true
		}
	}

	return false
}

func main() {
	defer w.Flush()

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

	for ; tc > 0; tc-- {
		fmt.Fscan(r, &n)
		a = make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(r, &a[i])
		}

		if !solve() {
			fmt.Fprintln(w, INIT)
		}
	}
}

package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

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

func lowerBound(arr []int, t int) int {
	lo := 0
	hi := len(arr)
	for lo < hi {
		mid := lo + (hi-lo)/2
		if arr[mid] >= t {
			hi = mid
		} else {
			lo = mid + 1
		}
	}
	return hi
}

const (
	INIT = -1
	INF  = int(1e9)
)

var (
	r      = bufio.NewReader(os.Stdin)
	w      = bufio.NewWriter(os.Stdout)
	exists = struct{}{} // for use with map[...]struct{}

	n int
	a []int64
)

func solve() bool {
	var sum int64
	has := make(map[int64][]int)
	for i := 0; i < n+2; i++ {
		sum += a[i]
		has[a[i]] = append(has[a[i]], i)
	}
	// fmt.Printf("has %+v\n", has)

	for i := 0; i < n+2; i++ {
		x := a[i]
		total := sum - x
		if (total % 2) != 0 {
			continue
		}
		half := total / 2

		if _, ok := has[half]; !ok {
			continue
		}

		for _, j := range has[half] {
			if j == i {
				continue
			}
			a[j], a[n] = a[n], a[j]
			a[i], a[n+1] = a[n+1], a[i]

			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", a[i])
			}
			fmt.Fprintln(w)
			return true
		}
	}

	return false
}

func main() {
	defer w.Flush()

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

	for ; tc > 0; tc-- {
		fmt.Fscan(r, &n)
		a = make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(r, &a[i])
		}

		if !solve() {
			fmt.Fprintln(w, INIT)
		}
	}
}

package main

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

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

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

func lowerBound(arr []int, t int) int {
	lo := 0
	hi := len(arr)
	for lo < hi {
		mid := lo + (hi-lo)/2
		if arr[mid] >= t {
			hi = mid
		} else {
			lo = mid + 1
		}
	}
	return hi
}

const (
	INIT = -1
	INF  = int(1e9)
)

var (
	r      = bufio.NewReader(os.Stdin)
	w      = bufio.NewWriter(os.Stdout)
	exists = struct{}{} // for use with map[...]struct{}

	n int
	a []int64
)

func solve() bool {
	var sum int64
	has := make(map[int64]int)
	for i := 0; i < n+2; i++ {
		sum += a[i]
		has[a[i]] = i
	}

	for i := 0; i < n+2; i++ {
		x := a[i]
		total := sum - x
		if (total % 2) != 0 {
			continue
		}
		half := total / 2

		if pos, ok := has[half]; ok {
			a[pos], a[n] = a[n], a[pos]
			a[i], a[n+1] = a[n+1], a[i]

			for i := 0; i < n; i++ {
				fmt.Fprintf(w, "%d ", a[i])
			}
			fmt.Fprintln(w)
			return true
		}
	}

	return false
}

func main() {
	defer w.Flush()

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

	for ; tc > 0; tc-- {
		fmt.Fscan(r, &n)
		a = make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(r, &a[i])
		}

		if !solve() {
			fmt.Fprintln(w, INIT)
		}
	}
}

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int64]int), make([]int64, n + 2)

		var sum int64
		for i, _ := range nums {
			Fscan(in, &nums[i])
			sum += nums[i]
			mp[nums[i]]++
		}

		pos := -1
		if sum & 0x1 == 0 {
			for i, val := range nums {
				if val & 0x1 == 0 {
					if (sum - val) / 2 != val || ((sum - val) / 2 == val && mp[val] > 1) {
						if mp[(sum - val) >> 1] != 0 {
							pos = i
							break
						}
					}
				}
			}

		} else {
			for i, val := range nums {
				if val & 0x1 == 1 {
					if (sum - val) / 2 != val || ((sum - val) / 2 == val && mp[val] > 1) {
						if mp[(sum - val) / 2] > 0 {
							pos = i
							break
						}
					}
				}
			}
		}

		if pos == -1 {
			Fprintln(out, -1)
		} else {
			cnt := 0
			for i, val := range nums {
				if (val != (sum - nums[pos]) / 2 || cnt != 0) && i != pos {
					Fprint(out, val, " ")
				}
				if val == (sum - nums[pos]) / 2 {
					cnt++
				}
			}
			Fprintln(out)
		}
	}
}

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

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

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

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

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		nums := make([]int, n + 3)

		for i, _ := range nums {
			if i == 0 {
				continue
			}
			Fscan(in, &nums[i])
		}

		sort.Ints(nums)
		for i, _ := range nums {
			if i == 0 {
				continue
			}
			nums[i] += nums[i-1]
		}

		if nums[n + 1] == 2 * nums[n] {
			for i := 1; i < n+1; i++ {
				Fprint(out, nums[i] - nums[i - 1], " ")
			}

		} else {
			var pos int
			target := nums[n + 2] - nums[n + 1]
			for pos = 1; pos < n + 2; pos++ {
				if target == nums[n + 1] - nums[pos] + nums[pos - 1] {
					break
				}
			}
			if pos == n + 2 {
				Fprint(out, -1)
			} else {
				for i := 1; i < pos; i++ {
					Fprint(out, nums[i] - nums[i - 1], " ")
				}
				for i := pos + 1; i < n + 2; i++ {
					Fprint(out, nums[i] - nums[i - 1], " ")
				}
			}
		}
		Fprintln(out)
	}
}

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

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

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

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

package main

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

	//"math"
	"os"
)

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		nums := make([]int, n + 3)

		for i, _ := range nums {
			if i == 0 {
				continue
			}
			Fscan(in, &nums[i])
		}

		sort.Ints(nums)
		for i, _ := range nums {
			if i == 0 {
				continue
			}
			nums[i] += nums[i-1]
		}

		if nums[n + 1] == 2 * nums[n] {
			for i := 1; i < n+1; i++ {
				Fprint(out, nums[i] - nums[i - 1], " ")
			}

		} else {
			var pos int
			target := nums[n + 2] - nums[n + 1]
			for pos = 1; pos < n + 3; pos++ {
				if target == nums[n + 1] - nums[pos] + nums[pos - 1] {
					break
				}
			}
			if pos == n + 3 {
				Fprint(out, -1)
			} else {
				for i := 1; i < pos; i++ {
					Fprint(out, nums[i] - nums[i - 1], " ")
				}
				for i := pos + 1; i < n + 2; i++ {
					Fprint(out, nums[i] - nums[i - 1], " ")
				}
			}
		}
		Fprintln(out)
	}
}

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

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

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

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

package main

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

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

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int64, n+2)
		for i := 0; i < n+2; i++ {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		var sum int64
		sum = 0

		for i := 0; i < n; i++ {
			sum += a[i]
		}

		if sum == a[n] {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, a[i], " ")
			}
			fmt.Fprintln(out)
		} else {
			sum += a[n]
			pos := -1
			for i := 0; i < n; i++ {
				if sum-a[i] == a[n+1] {
					pos = i
					break
				}
			}
			if pos == -1 {
				fmt.Fprintln(out, -1)
			} else {
				for i := 0; i < n+1; i++ {
					if pos != i {
						fmt.Fprint(out, a[i], " ")
					}

				}
				fmt.Fprintln(out)
			}
		}

	}

	var T int
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		fmt.Fscan(in, &n)
		v := []int{}
		freq := map[int]int{}
		var sum int64
		for i := 0; i<n+2 ; i++ {
			var x int
			fmt.Fscan(in, &x)
			v = append(v, x) //*
			freq[x]++
			sum += int64(x)
		}
		sort.Ints(v)
		ok := false
		for i, x := range v {
			rem := sum - int64(x)
			if rem % 2 == 1 {
				continue
			}
			rem /= 2
			need := 1
			if int(rem) == x {
				need++
			}
			if rem <= int64(v[n+1]) && freq[int(rem)] >= need {
				ok = true
				v[i] = -1
				sum = rem
				break
			}
		}
		if !ok {
			fmt.Println(-1)
			continue
		}
		for _, x := range v {
			if x != int(sum) && x!=-1{
				fmt.Printf("%d ", x)
			}
		}
		fmt.Println("")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n + 2)
		var sum int64 = 0
		for i := 0; i < n + 2; i++ {
			fmt.Fscan(in, &arr[i])
			sum = sum + int64(arr[i])
		}
		sort.Ints(arr)
		sum -= int64(arr[n + 1])
		var done = false
		for i := 0; i <= n; i++ {
			if sum - int64(arr[i]) == int64(arr[n + 1]) {
				for j := 0; j <= n; j++ {
					if i == j {
						continue
					}
					fmt.Fprint(out, arr[j], " ")
				}
				fmt.Fprintln(out, "")
				done = true
				break
			}
		}
		if done {
			t--
			continue
		}
		sum += int64(arr[n + 1])
		if sum - int64(arr[n]) == int64(arr[n]) {
			for i := 0; i < n; i++ {
				fmt.Fprint(out, arr[i], " ")
			}
			fmt.Fprintln(out, "")
			done = true
		}
		if done {
			t--
			continue
		}
		fmt.Fprintln(out, -1)
		t--
	}
	out.Flush()

}