package main

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

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

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

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

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

		a := make([]int, n)
		cnt := make(map[int]int)
		max_ := 0
		prev_max_ := 0
		max_t := 0
		for i := range a {
			fmt.Fscan(r, &a[i])
			max_ = max(max_, a[i])
			max_t = max_
			cnt[a[i]]++
		}

		fmt.Fprintf(w, "%d ", max_t)
		cnt[max_t]--

		for max_ != prev_max_ {
			// fmt.Fprintf(w, "*** max_:%d prev_max_:%d\n", max_, prev_max_)
			prev_max_ = max_
			for _, v := range a {
				/*
				fmt.Fprintf(
					w,
					"--- v:%d cnt[v]:%d\n",
					v, cnt[v])
					*/
				if cnt[v] > 0  && (prev_max_ | v) > max_ {
					max_ = prev_max_ | v
					max_t = v
				}
			}

			if cnt[max_t] > 0 {
				fmt.Fprintf(w, "%d ", max_t)
				cnt[max_t]--
			}
		}

		for _, v := range a {
			if cnt[v] > 0 {
				fmt.Fprintf(w, "%d ", v)
				cnt[v]--
			}
		}
		fmt.Fprintln(w, "")

	}

}

package main

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

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

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

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

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

func (io *IO) ReadTwoDigitsAndString() (int, int, string) {
	var a, b int
	var res string
	_, _ = fmt.Fscanf(io.in, "%d %d %s\n", &a, &b, &res)
	return a, b, res
}

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

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

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

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

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

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

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

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)

	t := io.ReadInt()
	for ; t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)

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

		now := a[0]

		for i := 1; i < len(a); i++ {
			maxPos := -1
			newNow := now

			for j := i; j < len(a); j++ {
				if now|a[j] > newNow {
					maxPos = j
					newNow = now | a[j]
				}
			}

			if maxPos != -1 {
				a.Swap(i, maxPos)
			} else {
				break
			}

			now = newNow
		}

		io.PrintlnIntSlice(a)
	}
}

package main

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

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

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

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

		a := make([]int, n)
		cnt := make(map[int]int)
		max_ := 0
		prev_max_ := 0
		max_t := 0
		for i := range a {
			fmt.Fscan(r, &a[i])
			if a[i] > max_ {
				max_ = a[i]
				max_t = a[i]
			}
			cnt[a[i]]++
		}

		fmt.Fprintf(w, "%d ", max_t)
		cnt[max_t]--

		for max_ != prev_max_ {
			prev_max_ = max_
			for _, v := range a {
				if cnt[v] > 0  && (prev_max_ | v) > max_ {
					max_ = prev_max_ | v
					max_t = v
				}
			}

			if cnt[max_t] > 0 {
				fmt.Fprintf(w, "%d ", max_t)
				cnt[max_t]--
			}
		}

		for _, v := range a {
			if cnt[v] > 0 {
				fmt.Fprintf(w, "%d ", v)
				cnt[v]--
			}
		}
		fmt.Fprintln(w, "")
	}

}

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		var n int
		Fscan(in, &n)
		var a, ok = []int{}, []int{}
		for i := 0; i < n; i++ {
			var x int
			Fscan(in, &x)
			a = append(a, x)
			ok = append(ok, 0)
		}
		var ans = []int{}
		now := 0
		for len(ans) < n {
			x, pos := 0, 0
			for i := 0; i < n; i++ {
				if ok[i] == 1 {
					continue
				}
				val := a[i] &^ now
				if val > x {
					x = val
					pos = i
				}
			}
			now |= x
			if x > 0 {
				ok[pos] = 1
				ans = append(ans, a[pos])
				continue
			}
			for i := 0; i < n; i++ {
				val := a[i] &^ now
				if val == x && ok[i] == 0 {
					ok[i] = 1
					ans = append(ans, a[i])
				}
			}
		}
		for i := 0; i < n; i++ {
			Fprintf(out, "%d ", ans[i])
		}
		Fprintf(out, "\n")
	}
}

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

package main

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

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

func readInt() int {
	var i int
	fmt.Fscan(reader, &i)
	return i
}

func readString() string {
	var s string
	fmt.Fscan(reader, &s)
	return s
}

func main(){
	defer writer.Flush()
	T := readInt()
	for i := 1; i <= T; i++{
		n := readInt()
		a := make([]int, n)
		for j := 0; j < n; j++ {
			a[j] = readInt()
		}
		cur := 0
		for i := 0; i < n; i++ {
			change, p1 := 0, 0
			for j := 0; j < len(a); j++ {
				nCur := cur | a[j]
				if nCur > change {
					change = nCur
					p1 = j
				}
			}
			if change == cur {
				break
			}

			fmt.Fprint(writer, a[p1], " ")
			a = append(a[:p1], a[p1+1:]...)
			cur = change
		}
		for i := 0; i < len(a); i++ {
			fmt.Fprint(writer, a[i], " ")
		}
		fmt.Fprintln(writer)
	}
}

package main

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

const mod = 998244353
const mx = int64(1e9 + 7)

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	Fscan(in, &n)
	arr := make([][]int64, n)
	for i := 0; i < n; i++ {
		var item int64
		Fscan(in, &item)
		arr[i] = []int64{item, item}
	}
	cur := int64(0)
	for i := 0; i < 30 && i < len(arr); i++ {
		sort.Slice(arr[i:], func(l, r int) bool {
			return arr[l+i][1] > arr[r+i][1]
		})
		cur |= arr[i][0]
		for j := i + 1; j < n; j++ {
			arr[j][1] -= arr[j][1] & cur
		}
	}
	for i := 0; i < len(arr); i++ {
		Fprintf(out, "%d ", arr[i][0])
	}
	Fprintln(out)
}

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

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

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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

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

	var T int
	var n int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		r := make([]int, n)
		ans := make([]int, n)
		mi := 0
		ua := map[int]bool{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			r[i] = x
			if x > r[mi] {
				mi = i
			}
		}
		ans[0] = r[mi]
		ua[mi] = true

		mx := r[mi]
		mxi := 0
		for l := 1; l < 31; l++ {
			t := mx
			for i, v := range r {
				if v|mx > t {
					t = v | mx
					mxi = i
				}
			}
			if t == mx {
				break
			}
			mx = t
			ua[mxi] = true
			ans[l] = r[mxi]
		}

		idx := len(ua)
		for i, v := range r {
			if ua[i] {
				continue
			}
			ans[idx] = v
			idx++
		}

		for _, v := range ans {
			Fprintf(out, "%d ", v)
		}
		Fprintln(out, "")
	}
}

package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		type pair struct{ ori, cur int }
		a := make([]pair, n)
		or := 0
		for i := range a {
			Fscan(in, &a[i].ori)
			a[i].cur = a[i].ori
			or |= a[i].ori
		}
		mask := 0
		pre := []int{}
		for mask != or {
			mxI := 0
			for i, p := range a {
				if p.cur > a[mxI].cur {
					mxI = i
				}
			}
			mask |= a[mxI].cur
			pre = append(pre, a[mxI].ori)
			a = append(a[:mxI], a[mxI+1:]...)
			for i := range a {
				a[i].cur &^=mask
			}
		}
		for _, v := range pre {
			Fprint(out, v, " ")
		}
		for _, v := range a {
			Fprint(out, v.ori, " ")
		}
		Fprintln(out)
	}

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

	// 如果是多组数据，请务必加上这段保险 —— 已经无法统计，有多少位竞赛选手在漏读数据上损失大把分数（包括我）
	// 此外，如果不小心写成了 scan(v) 而不是 scan(&v)，由于未传入指针，不会读入任何数据，这样本地运行一次就能立马发现错误
	leftData, _ := ioutil.ReadAll(in)
	if s := strings.TrimSpace(string(leftData)); s != "" {
		panic("有未读入的数据：\n" + s)
	}

}

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

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

package main

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

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

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

		aa := make([]int, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

		bb := make([]bool, n)
		var z int
		for i := 31; i > 0; i-- {
			if z&(1<<(i-1)) > 0 {
				continue
			}

			d := -1
			var idx int
			for j, v := range aa {
				if bb[j] {
					continue
				}

				if v|z > d {
					d = v | z
					idx = j
				}
			}

			if d < 0 {
				break
			}
			z = d
			bb[idx] = true
			fmt.Fprintf(out, "%d ", aa[idx])
		}

		for i := range bb {
			if bb[i] {
				continue
			}
			fmt.Fprintf(out, "%d ", aa[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

		aa := make([]int, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

		bb := make([]bool, n)
		var z int
		for i := 31; i > 0; i-- {
			if z&(1<<(i-1)) > 0 {
				continue
			}

			d := -1
			var idx int
			for j, v := range aa {
				if bb[j] {
					continue
				}

				if v|z > d {
					d = v | z
					idx = j
				}
			}

			if d < 0 {
				break
			}
			z = d
			bb[idx] = true
			fmt.Fprintf(out, "%d ", aa[idx])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

		aa := make([]int, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

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

		bb := make([]bool, n)
		fmt.Fprintf(out, "%d ", aa[0])
		z := aa[0]
		for i := 1; i < n; i++ {
			if bb[i] {
				continue
			}

			var d int
			var idx int
			for j := 1; j < n; j++ {
				if bb[j] {
					continue
				}

				if aa[j]|z > d {
					d = aa[j] | z
					idx = j
				}
			}
			z = d
			bb[idx] = true
			fmt.Fprintf(out, "%d ", aa[idx])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

		aa := make([]int, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

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

		bb := make([]bool, n)
		bb[0] = true
		var z int
		for i := 0; i < bits.Len(uint(aa[0])); i++ {
			z = (z << 1) | 1
		}
		z = z ^ aa[0]
		fmt.Fprintf(out, "%d ", aa[0])
		stack := []int{}
		for i := 1; i < n; i++ {
			if aa[i] != aa[i-1] && aa[i]&z > 0 {
				bb[i] = true
				stack = append(stack, aa[i])
			}
		}

		sort.Slice(stack, func(i, j int) bool {
			return stack[i]|aa[0] > stack[j]|aa[0]
		})

		for _, v := range stack {
			fmt.Fprintf(out, "%d ", v)
		}
		for i := 1; i < n; i++ {
			if bb[i] {
				continue
			}
			fmt.Fprintf(out, "%d ", aa[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

		aa := make([]int, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

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

		bb := make([]bool, n)
		bb[0] = true
		var z int
		for i := 0; i < bits.Len(uint(aa[0])); i++ {
			z = (z << 1) | 1
		}
		z = z ^ aa[0]
		fmt.Fprintf(out, "%d ", aa[0])
		for i := 1; i < n; i++ {
			if aa[i] != aa[i-1] && aa[i]&z > 0 {
				bb[i] = true
				fmt.Fprintf(out, "%d ", aa[i])
			}
		}

		for i := 1; i < n; i++ {
			if bb[i] {
				continue
			}
			fmt.Fprintf(out, "%d ", aa[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

		aa := make([]int, n)
		for i := range aa {
			fmt.Fscan(in, &aa[i])
		}

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

		bb := make([]bool, n)
		bb[0] = true
		var z int
		for i := 0; i < bits.Len(uint(aa[0])); i++ {
			z = (z << 1) | 1
		}
		z = z ^ aa[0]
		fmt.Fprintf(out, "%d ", aa[0])
		for i := 1; i < n; i++ {
			if aa[i]&z > 0 {
				bb[i] = true
				fmt.Fprintf(out, "%d ", aa[i])
			}
		}

		for i := 1; i < n; i++ {
			if bb[i] {
				continue
			}
			fmt.Fprintf(out, "%d ", aa[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

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

func (io *IO) ReadTwoDigitsAndString() (int, int, string) {
	var a, b int
	var res string
	_, _ = fmt.Fscanf(io.in, "%d %d %s\n", &a, &b, &res)
	return a, b, res
}

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

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

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

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

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

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

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

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)

	t := io.ReadInt()
	for ; t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)

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

		now := a[0]

		for i := 1; ; i++ {
			maxPos := -1
			newNow := now

			for j := i; j < len(a); j++ {
				if newNow|a[j] > newNow {
					maxPos = j
					newNow |= a[j]
				}
			}

			if maxPos != -1 {
				a[i], a[maxPos] = a[maxPos], a[i]
			} else {
				break
			}

			now = newNow
		}

		io.PrintlnIntSlice(a)
	}
}

package main

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

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

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

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

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

func (io *IO) ReadTwoDigitsAndString() (int, int, string) {
	var a, b int
	var res string
	_, _ = fmt.Fscanf(io.in, "%d %d %s\n", &a, &b, &res)
	return a, b, res
}

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

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

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

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

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

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

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

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)

	t := io.ReadInt()
	for ; t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)

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

		now := a[0]

		for i := 1; ; i++ {
			maxPos := -1
			newNow := now

			for j := i; j < len(a); j++ {
				newNewNow := newNow | a[j]
				if newNewNow > newNow {
					maxPos = j
					newNow = newNewNow
				}
			}

			if maxPos != -1 {
				a[i], a[maxPos] = a[maxPos], a[i]
			} else {
				break
			}

			now = newNow
		}

		io.PrintlnIntSlice(a)
	}
}

package main

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

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

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

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

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

func (io *IO) ReadTwoDigitsAndString() (int, int, string) {
	var a, b int
	var res string
	_, _ = fmt.Fscanf(io.in, "%d %d %s\n", &a, &b, &res)
	return a, b, res
}

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

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

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

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

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

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

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

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

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)

	t := io.ReadInt()
	for ; t > 0; t-- {
		n := io.ReadInt()
		a := io.ReadIntSlice(n)

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

		now := a[0]

		for i := 1; ; i++ {
			maxPos := -1
			newNow := now

			for j := i; j < len(a); j++ {
				newNewNow := now | a[j]
				if newNewNow > newNow {
					maxPos = j
					newNow = newNewNow
				}
			}

			if maxPos != -1 {
				a[i], a[maxPos] = a[maxPos], a[i]
			} else {
				break
			}
		}

		io.PrintlnIntSlice(a)
	}
}

package main

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

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

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

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

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

		a := make([]int, n)
		cnt := make(map[int]int)
		max_ := 0
		prev_max_ := 0
		max_t := 0
		for i := range a {
			fmt.Fscan(r, &a[i])
			max_ = max(max_, a[i])
			max_t = max_
			cnt[a[i]]++
		}

		fmt.Fprintf(w, "%d ", max_t)
		cnt[max_t]--

		for max_ != prev_max_ {
			// fmt.Fprintf(w, "*** max_:%d prev_max_:%d\n", max_, prev_max_)
			prev_max_ = max_
			for _, v := range a {
				/*
				fmt.Fprintf(
					w,
					"--- v:%d cnt[v]:%d\n",
					v, cnt[v])
					*/
				if cnt[v] > 0  && (max_ | v) > max_ {
					max_ = max_ | v
					max_t = v
				}
			}

			if cnt[max_t] > 0 {
				fmt.Fprintf(w, "%d ", max_t)
				cnt[max_t]--
			}
		}

		for _, v := range a {
			if cnt[v] > 0 {
				fmt.Fprintf(w, "%d ", v)
				cnt[v]--
			}
		}
		fmt.Fprintln(w, "")

	}

}

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		var n int
		Fscan(in, &n)
		var a, ok = []int{}, []int{}
		for i := 0; i < n; i++ {
			var x int
			Fscan(in, &x)
			a = append(a, x)
			ok = append(ok, 0)
		}
		var ans = []int{}
		now := 0
		for len(ans) < n {
			x, pos := 0, 0
			for i := 0; i < n; i++ {
				if ok[i] == 1 {
					continue
				}
				val := a[i] &^ now
				if val > x {
					x = val
					pos = i
				}
			}
			now = x
			if x > 0 {
				ok[pos] = 1
				ans = append(ans, a[pos])
				continue
			}
			for i := 0; i < n; i++ {
				val := a[i] &^ now
				if val == x && ok[i] == 0 {
					ok[i] = 1
					ans = append(ans, a[i])
				}
			}
		}
		for i := 0; i < n; i++ {
			Fprintf(out, "%d ", ans[i])
		}
		Fprintf(out, "\n")
	}
}

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


/*
Attempting https://codeforces.com/contest/1384/problem/B2
which will take care of B1 also, if works
*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line1, _ := reader.ReadString('\n')
	line1_arr := strings.Fields(line1)
	// fmt.Println(line1_arr)
	T, _ := strconv.Atoi(line1_arr[0])
	//fmt.Println("T:", T)
	for t := 0; t < T; t++ {
		line2, _ := reader.ReadString('\n')
		line2_arr := strings.Fields(line2)
		N, _ := strconv.Atoi(line2_arr[0])
		K, _ := strconv.Atoi(line2_arr[1])
		L, _ := strconv.Atoi(line2_arr[2])
		// fmt.Println(N, K, L)
		line3, _ := reader.ReadString('\n')
		Astr := strings.Fields(line3)
		A := make([]int, N)
		var safe []int
		soln_possible := true
		for i:=0; i<N; i++ {
			A[i], _ = strconv.Atoi(Astr[i])
			if A[i] + K <= L {
				safe = append(safe, i)
			} else if A[i] > L {
				fmt.Println("No")
				soln_possible = false
				break
			}
		}
		//fmt.Println("A:", A)
		//fmt.Println("safe:", safe)

		if !soln_possible {
			continue
		}

		safe_ind := 0
		lower_bound := -1
		upper_bound := N
		if len(safe) > 0 {
			upper_bound = safe[safe_ind]
		}
		res := "Yes"
		for true {

			retval := is_path_safe(lower_bound, upper_bound, K, L, A)
			//fmt.Println("is_path_safe() beg: ", lower_bound, "end: ", upper_bound, "retval: ", retval)
			if !retval {
				res = "No"
				break
			} else {
				if safe_ind > len(safe) -1 {
					break
				}

				lower_bound = safe[safe_ind]
				safe_ind++
				if safe_ind > len(safe) -1 {
					upper_bound = N
				} else {
					upper_bound = safe[safe_ind]
				}
			}
		}

		fmt.Println(res)
	}
}

func is_path_safe(beg, end, K, L int, A []int) bool {
	abeg := beg + 1
	aend := end - 1
	if abeg >= aend {
		return true
	}

	t := 0
	for i:=abeg; i<=aend; i++ {
		t = get_time_to_enter(K, L, t, A[i])
		//fmt.Println("t: ", t)
		if t < 0 {
			return false
		}
	}

	// last step
	t++

	//fmt.Println("t: ", t)
	if t > 2*K {
		return false
	}

	return true
}

/*
The precise time pos, where we can enter that position
*/
func get_time_to_enter(K, L, t, d int) int {

	t++
	x := d + K - L
	if t >= x && t <= 2 * K - x {
		return t
	} else if t < x {
		return x
	} else {
		return -1
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

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

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

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

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

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

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

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

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

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

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

type tide struct {
	d int64 // delta
	i bool  // increasing - false by default
}

// Next adjusts the tide level to the next most optimal value
// Returns false if unable to do so
func (t *tide) Next(currDepth int64, k, l int64) bool {
	// rest spot -> reset params
	if currDepth + k <= l {
		t.d = k
		t.i = false
		return true
	}

	// tide decreasing -> check min
	if !t.i {
		t.d--
		if currDepth + t.d > l {
			t.d = l - currDepth
		}
		if t.d < 0 {
			return false
		}
		if t.d == 0 {
			t.i = true
		}
		return true
	}

	// tide increasing
	t.d++
	if currDepth + t.d > l {
		return false
	}
	if t.d == k {
		t.i = false
	}
	return true
}

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

func sol(d []int64, n, k, l int64) string {
	t := &tide{
		d: k,
		i: false,
	}
	for _, di := range d {
		if !t.Next(di, k, l) {
			return "No"
		}
	}
	return "Yes"
}

/*
Attempting https://codeforces.com/contest/1384/problem/B2
which will take care of B1 also, if works
*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line1, _ := reader.ReadString('\n')
	line1_arr := strings.Fields(line1)
	// fmt.Println(line1_arr)
	T, _ := strconv.Atoi(line1_arr[0])
	//fmt.Println("T:", T)
	for t := 0; t < T; t++ {
		line2, _ := reader.ReadString('\n')
		line2_arr := strings.Fields(line2)
		N, _ := strconv.Atoi(line2_arr[0])
		K, _ := strconv.Atoi(line2_arr[1])
		L, _ := strconv.Atoi(line2_arr[2])
		// fmt.Println(N, K, L)
		line3, _ := reader.ReadString('\n')
		Astr := strings.Fields(line3)
		A := make([]int, N)
		var safe []int
		soln_possible := true
		for i:=0; i<N; i++ {
			A[i], _ = strconv.Atoi(Astr[i])
			if A[i] + K <= L {
				safe = append(safe, i)
			} else if A[i] > L {
				fmt.Println("No")
				soln_possible = false
				break
			}
		}
		//fmt.Println("A:", A)
		//fmt.Println("safe:", safe)

		if !soln_possible {
			continue
		}

		safe_ind := 0
		lower_bound := -1
		upper_bound := N
		if len(safe) > 0 {
			upper_bound = safe[safe_ind]
		}
		res := "Yes"
		for true {

			retval := is_path_safe(lower_bound, upper_bound, K, L, A)
			//	fmt.Println("is_path_safe() beg: ", lower_bound, "end: ", upper_bound, "retval: ", retval)
			if !retval {
				res = "No"
				break
			} else {
				if safe_ind > len(safe) -1 {
					break
				}

				lower_bound = safe[safe_ind]
				safe_ind++
				if safe_ind > len(safe) -1 {
					upper_bound = N
				} else {
					upper_bound = safe[safe_ind]
				}
			}
		}

		fmt.Println(res)
	}
}

func is_path_safe(beg, end, K, L int, A []int) bool {
	abeg := beg + 1
	aend := end - 1
	if abeg >= aend {
		return true
	}

	t := 0
	k := K
	for i:=abeg; i<=aend; i++ {
		x := A[i] + k - L
		if x > 0 {
			t += x
			k = get_k_phase(K, k, t)
		} else {
			t++
		}

	}

	// fmt.Println("t: ", t)
	if t >= 2*K {
		return false
	}

	return true
}

func get_k_phase(K, k, t int) int {
	t %= 2*K
	if t <= K {
		return k - t
	} else {
		return k
	}
}


package main

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

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

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

func solve(a []int) {

	max := 0
	sndMax := 0
	for _, v := range a {
		if v > max {
			sndMax = max
			max = v
		} else if v > sndMax && v != max {
			sndMax = v
		}
	}

	count := 0
	for _, v := range a {
		if v == max {
			count++
		}
	}

	if count == 2 {
		printf("YES\n")
		printf("%d %d %d\n", max, sndMax, 1)
	} else if count == 3 {
		printf("YES\n")
		printf("%d %d %d\n", max, max, max)
	} else {
		printf("NO\n")
	}

}

func main() {
	defer writer.Flush()

	var testCases int
	scanf("%d\n", &testCases)
	for i := 0; i < testCases; i++ {
		var x, y, z int
		scanf("%d %d %d", &x, &y, &z)
		// printf("%d %d %d\n", x, y, z)
		scanf("\n")
		solve([]int{x, y, z})
	}
}

package main

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

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

	testCountStr, _ := reader.ReadString('\n')
	testCountStr = strings.Trim(testCountStr, " \r\n")
	testCountVal64, _ := strconv.ParseInt(testCountStr, 10, 32)
	testCountVal := int(testCountVal64)

	for i := 0; i < testCountVal; i++ {
		val1Str, _ := reader.ReadString(' ')
		val2Str, _ := reader.ReadString(' ')
		val3Str, _ := reader.ReadString('\n')

		val1, _ := strconv.ParseInt(strings.Trim(val1Str, " \r\n"), 10, 32)
		val2, _ := strconv.ParseInt(strings.Trim(val2Str, " \r\n"), 10, 32)
		val3, _ := strconv.ParseInt(strings.Trim(val3Str, " \r\n"), 10, 32)

		switch {
		case val1 == val2 && val2 == val3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val1, val1)
			}
		case val1 == val2 && val3 < val1:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val3, val3)
			}
		case val3 == val2 && val1 < val3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val1, val3)
			}
		case val1 == val3 && val2 < val1:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val2, val2)
			}
		default:
			{
				fmt.Println("NO")
			}
		}
	}
}

package main

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

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.nextInt(); t > 0; t-- {
		a := []int{io.nextInt(), io.nextInt(), io.nextInt()}
		sort.Ints(a)
		if a[1] == a[2] {
			io.println("YES")
			io.println(a[0], a[0], a[1])
		} else {
			io.println("NO")
		}
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p []byte
}

func newFastIO(r io.Reader, w io.Writer) fastIO {
	return fastIO{bufio.NewReader(r), bufio.NewWriter(w), make([]byte, 1)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p)
	for !('0' <= f.p[0] && f.p[0] <= '9') {
		f.Read(f.p)
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p)
	}
	return n
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

// https://codeforces.com/contest/x/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input *bufio.Reader

func main() {
	var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

var x, y, z int
func solver() {
	fmt.Fscan(input, &x, &y, &z)

	if x == y && z <= x {
		fmt.Println("YES")
		fmt.Println(x, z, z)
	} else if x == z && y <= z {
		fmt.Println("YES")
		fmt.Println(x, y, y)
	} else if z == y && x <= z {
		fmt.Println("YES")
		fmt.Println(z, x, x)
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 1024*1024)
	scanner.Split(bufio.ScanWords)

	input := func() int {
		scanner.Scan()
		i, _ := strconv.Atoi(scanner.Text())
		return i
	}

	for t := input(); t > 0; t-- {
		arr := make([]int, 3)

		for i := range arr {
			arr[i] = input()
		}

		sort.Ints(arr)

		if arr[2] == arr[1] {
			fmt.Println("YES")
			fmt.Println(arr[0], arr[0], arr[2])
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var x, y, z int
		fmt.Fscan(in, &x)
		fmt.Fscan(in, &y)
		fmt.Fscan(in, &z)

		if x == y && x == z {
			fmt.Println("YES")
			fmt.Printf("%d %d %d\n", x, x, x)
		} else if x == y && x > z {
			fmt.Println("YES")
			fmt.Printf("%d %d %d\n", z, z, x)
		} else if x == z && x > y {
			fmt.Println("YES")
			fmt.Printf("%d %d %d\n", y, y, x)
		} else if y == z && y > x {
			fmt.Println("YES")
			fmt.Printf("%d %d %d\n", x, x, y)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		var x, y, z int64
		line := readLine(reader)
		strs := strings.Split(string(line), " ")
		x, _ = strconv.ParseInt(strs[0], 10, 64)
		y, _ = strconv.ParseInt(strs[1], 10, 64)
		z, _ = strconv.ParseInt(strs[2], 10, 64)
		if x != y && x != z && y != z {
			fmt.Println("NO")
			continue
		}
		if x == y && z > x || (x == z && y > x) || (y == z && x > y) {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
		if x == y && x == z {
			fmt.Println(x, y, z)
			continue
		}
		if x == y {
			fmt.Println(x, z, z)
		} else if x == z {
			fmt.Println(y, x, y)
		} else {
			fmt.Println(x, x, z)
		}
	}
}

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

package main

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

func main() {
	defer writer.Flush()
	t := NextInt()
	for t > 0 {
		t--
		a := make([]int, 3)
		for i := 0; i < 3; i++ {
			a[i] = NextInt()
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		if a[0] == a[2] {
			Println("YES")
			Print(a[0])
			Print(" ")
			Print(a[0])
			Print(" ")
			Println(a[0])
		} else if a[1] == a[2] {
			Println("YES")
			Print(a[0])
			Print(" ")
			Print(a[0])
			Print(" ")
			Println(a[1])
		} else {
			Println("NO")
		}
	}
}

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

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

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

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

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

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

func main() {
	defer out.Flush()
	var nTest int
	fmt.Fscanf(in, "%d\n", &nTest)
	for i := 0; i < nTest; i++ {
		solveCase()
	}
}
func solveCase() {
	var a [3]int
	fmt.Fscanf(in, "%d %d %d\n", &a[0], &a[1], &a[2])
	sort.Ints(a[:])
	if a[1] != a[2] {
		fmt.Fprint(out, "NO\n")
	} else {
		fmt.Fprint(out, "YES\n")
		fmt.Fprintf(out, "%d %d %d\n", a[0], a[0], a[1])
	}
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

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

	for _case := 1; _case <= T; _case++ {
		input := readInts()
		sort.Ints(input)
		if input[0] == input[2] {
			fmt.Printf("YES\n%d %d %d\n", input[0], input[0], input[0])
		} else if input[1] == input[2] {
			fmt.Printf("YES\n%d %d %d\n", input[0], input[0], input[1])
		} else {
			fmt.Println("NO")
		}
		//fmt.Fprintf(writer, "Case #%d: %d %d\n", _case, x, y)
	}

	writer.Flush()
}

func readInts() []int {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

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

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

package main

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

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

	t, a := 0, make([]int, 3)
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &a[0], &a[1], &a[2])
		sort.Ints(a)
		if a[1] < a[2] {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
			Fprintln(out, a[0], a[0], a[1])
		}
	}
}

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

package main

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

func solve() {
	x, y, z := readInt(), readInt(), readInt()

	if x == y && y == z {
		fmt.Println("YES")
		fmt.Println(x, x, x)
		return
	}

	if x != y && y != z && z != x {
		fmt.Println("NO")
		return
	}

	if x == y {
		if x > z {
			fmt.Println("YES")
			fmt.Println(x, z, z)
		} else {
			fmt.Println("NO")
		}
	} else if y == z {
		if y > x {
			fmt.Println("YES")
			fmt.Println(x, x, z)
		} else {
			fmt.Println("NO")
		}
	} else if z == x {
		if x > y {
			fmt.Println("YES")
			fmt.Println(y, x, y)
		} else {
			fmt.Println("NO")
		}
	}
}

func main() {
	k := readInt()
	for i := 0; i < k; i++ {
		solve()
	}
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

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

func readInt() int {
	return int(readInt64())
}

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

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

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

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

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

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

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}

package main

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

func main() {
	var t uint16
	var x, y, z uint32
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &t)
	for i := uint16(0); i < t; i++ {
		fmt.Fscanf(in, "%d %d %d\n", &x, &y, &z)
		if x == y {
			if z <= x {
				fmt.Println("YES")
				fmt.Println(z, z, y)
			} else {
				fmt.Println("NO")
			}
		} else if x == z {
			if y <= x {
				fmt.Println("YES")
				fmt.Println(y, y, x)
			} else {
				fmt.Println("NO")
			}
		} else if y == z {
			if x <= y {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var t, x, y, z int
	scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		scanf("%d %d %d\n", &x, &y, &z)
		cnt, max := 1, 0
		if x > max {
			max = x
			cnt = 1
		}
		if y > max {
			max = y
			cnt = 1
		} else if y == max {
			cnt++
		}

		if z > max {
			max = z
			cnt = 1
		} else if z == max {
			cnt++
		}

		if cnt == 1 {
			printf("NO\n")
		} else if cnt == 3 {
			printf("YES\n%d %d %d\n", x, y, z)
		} else {
			printf("YES\n")
			if x != max {
				printf("%d %d %d\n", x, x, max)
			} else if y != max {
				printf("%d %d %d\n", y, max, y)
			} else {
				printf("%d %d %d\n", max, z, z)
			}
		}
	}

}

package main

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

func main() {
	var t int
	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)
	fmt.Fscanln(scr, &t)

	for i := 0; i < t; i++ {
		a := make([]int, 3)
		fmt.Fscanln(scr, &a[0], &a[1], &a[2])

		sort.Ints(a)
		if a[2] != a[1] {
			fmt.Fprintln(ocr, "NO")
		} else {
			fmt.Fprintln(ocr, "YES")
			fmt.Fprintln(ocr, a[2], 1, a[0])
		}
		ocr.Flush()
	}
}

package main

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

func main() {
	var t int
	var a [3]int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		m := max(a[0], a[1])
		m = max(m, a[2])
		min := a[0]
		count := 0
		for j := 0; j < 3; j++ {
			if m == a[j] {
				count++
			} else {
				min = a[j]
			}
		}
		if count >= 2 {
			fmt.Println("YES")
			fmt.Printf("%d %d %d\n", m, min, min)
		} else {
			fmt.Println("NO")
		}
	}
}

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

package main
// https://codeforces.com/contest/1380/submission/87050098
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

import (
	"sort"
)

type FastIn struct {
	scanner *bufio.Scanner
}

func MakeFastIn() (obj FastIn)  {
	obj = FastIn{}
	obj.scanner = bufio.NewScanner(os.Stdin)
	obj.scanner.Split(bufio.ScanWords)
	return
}

func (fi *FastIn) ReadText() string {
	fi.scanner.Scan()
	return fi.scanner.Text()
}

func (fi *FastIn) ReadInt() int {
	ret, err := strconv.Atoi(fi.ReadText())
	if err != nil {
		panic(err)
	}
	return ret
}

func (fi *FastIn) ReadInts(arr []int) {
	for i := 0; i < len(arr); i++ {
		arr[i] = fi.ReadInt()
	}
}
func Min (a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func (fi *FastIn) ReadInt64() int64 {
	ret, err := strconv.ParseInt(fi.ReadText(), 10, 64)
	if err != nil {
		panic(err)
	}
	return ret
}

var x,k,y int64

func GetCost(arr []int, left_b int, right_b int) (int64, bool) {
	any_gt := false
	max_bound := left_b
	if max_bound < right_b {
		max_bound = right_b
	}
	for _,v := range arr {
		if  v > max_bound {
			any_gt = true
		}
	}

	len := int64(len(arr))
	if any_gt {
		if len < k {
			return 0, false
		}
		return Min((len/k)*x+(len%k)*y,x+(len-k)*y), true
	} else {
		return Min((len/k)*x+(len%k)*y, len * y), true
	}
}

func main() {
	fin := MakeFastIn()
	T := fin.ReadInt()
	for ;T>0;T--{
		a:= make([]int, 3)
		fin.ReadInts(a)

		sort.Ints(a[:])
		if a[1]==a[2] {
			fmt.Println("YES")
			fmt.Println(a[0],a[1],1)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	defer writer.Flush()
	t := NextInt()
	for t > 0 {
		t--
		a := make([]int, 3)
		for i := 0; i < 3; i++ {
			a[i] = NextInt()
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		if a[0] == a[2] {
			Println("YES")
			Print(a[0])
			Print(" ")
			Print(a[0])
			Print(" ")
			Println(a[0])
		} else if a[1] == a[2] {
			Println("YES")
			Print(a[1]-1)
			Print(" ")
			Print(a[1])
			Print(" ")
			Println(a[2])
		} else {
			Println("NO")
		}
	}
}

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

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

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

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

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

func main() {
	defer writer.Flush()
	t := NextInt()
	for t > 0 {
		t--
		a := make([]int, 3)
		for i := 0; i < 3; i++ {
			a[i] = NextInt()
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		if a[0] == a[2] {
			Println("YES")
			Print(a[0])
			Print(" ")
			Print(a[0])
			Print(" ")
			Println(a[0])
		} else if a[1] == a[2] {
			Println("YES")
			Print(a[0]-1)
			Print(" ")
			Print(a[0])
			Print(" ")
			Println(a[1])
		} else {
			Println("NO")
		}
	}
}

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

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

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

func Next() string {
	sc.Scan()
	return sc.Text()
}

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

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 0
	filename := "input.txt"
	if  debug != 0 {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

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

	for _case := 1; _case <= T; _case++ {
		input := readInts()
		sort.Ints(input)
		if input[0] == input[2] {
			fmt.Printf("YES\n%d %d %d\n", input[0], input[0], input[0])
		} else if input[1] == input[2] {
			fmt.Printf("YES\n%d %d %d\n", input[0]-1, input[0], input[1])
		} else {
			fmt.Println("NO")
		}
		//fmt.Fprintf(writer, "Case #%d: %d %d\n", _case, x, y)
	}

	writer.Flush()
}

func readInts() []int {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

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

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

package main

import (
	"fmt"
	"sort"
)

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

	for i := 0; i < t; i++ {
		a := make([]int, 3)
		fmt.Scanln(&a[0], &a[1], &a[2])

		m := make(map[int]int)
		m[a[0]]++
		m[a[1]]++
		m[a[2]]++

		sort.Ints(a)

		if len(m) == 3 {
			fmt.Println("NO")
		} else {
			if m[a[2]] >= 2 {
				fmt.Println("YES")
				fmt.Println(a[2], a[2]-1, a[0])
			} else {
				fmt.Println("NO")
			}
		}

	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var T int
	fmt.Scanf("%d", &T)
	for ;T>0;T--{
		var a[3] int
		for i:=0 ;i<3;i++{
			fmt.Scanf("%d", &a[i])
		}
		sort.Ints(a[:])
		if a[1]==a[2] {
			fmt.Println("YES")
			fmt.Println(a[0],a[1],1)
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"
import "math"

func main() {
	var testCount int

	fmt.Scanf("%d", &testCount)

	for i := 0; i < testCount; i++ {
		inputCount := 3
		vals := make([]int, 3)

		for j := 0; j < inputCount; j++ {
			fmt.Scanf("%d", &vals[j])
		}

		var max = -999
		var min = 2000000000
		for j := 0; j < inputCount; j++ {
			max = int(math.Max(float64(max), float64(vals[j])))
			min = int(math.Min(float64(min), float64(vals[j])))
		}
		var maxAppearTimes = 0
		for j := 0; j < inputCount; j++ {
			if vals[j] == max {
				maxAppearTimes++
			}
		}

		switch {
		case maxAppearTimes == 2:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d", max, min, min)
			}
		case maxAppearTimes == 3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d", max, max, max)
			}
		default:
			{
				fmt.Println("NO")
			}
		}

		// 1 2 3: 2 3 3
		// 1 1 3: 1 3 3
		// 1 3 3: 3 3 3
		// 3 3 3: 3 3 3
	}
}

package main

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

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

	testCountStr, _ := reader.ReadString('\n')
	testCountVal64, _ := strconv.ParseInt(testCountStr, 10, 32)
	testCountVal := int(testCountVal64)

	for i := 0; i < testCountVal; i++ {
		val1Str, _ := reader.ReadString(' ')
		val2Str, _ := reader.ReadString(' ')
		val3Str, _ := reader.ReadString('\n')

		val1, _ := strconv.ParseInt(val1Str, 10, 32)
		val2, _ := strconv.ParseInt(val2Str, 10, 32)
		val3, _ := strconv.ParseInt(val3Str, 10, 32)

		switch {
		case val1 == val2 && val2 == val3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val1, val1)
			}
		case val1 == val2:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val1, val3)
			}
		case val3 == val2:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val3, val3)
			}
		case val1 == val3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", val1, val1, val2)
			}
		default:
			{
				fmt.Println("NO")
			}
		}
	}
}

package main

import "fmt"
import "math"

func main() {
	var testCount int

	fmt.Scanf("%d", &testCount)

	for i := 0; i < testCount; i++ {
		inputCount := 3
		vals := make([]int, 3)

		for j := 0; j < inputCount; j++ {
			fmt.Scanf("%d", &vals[j])
		}

		var max = -999
		var min = 2000000000
		for j := 0; j < inputCount; j++ {
			max = int(math.Max(float64(max), float64(vals[j])))
			min = int(math.Min(float64(min), float64(vals[j])))
		}
		var maxAppearTimes = 0
		for j := 0; j < inputCount; j++ {
			if vals[j] == max {
				maxAppearTimes++
			}
		}

		switch {
		case maxAppearTimes == 2:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", max, min, min)
			}
		case maxAppearTimes == 3:
			{
				fmt.Println("YES")
				fmt.Printf("%d %d %d\n", max, max, max)
			}
		default:
			{
				fmt.Println("NO")
			}
		}

		// 1 2 3: 2 3 3
		// 1 1 3: 1 3 3
		// 1 3 3: 3 3 3
		// 3 3 3: 3 3 3
	}
}

// https://codeforces.com/contest/x/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input *bufio.Reader

func main() {
	var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

var x, y, z int
func solver() {
	fmt.Fscan(input, &x, &y, &z)

	if x == y && z <= x {
		fmt.Println("YES")
		fmt.Println(x, z, z)
	} else if x == z && y <= z {
		fmt.Println("YES")
		fmt.Println(x, z, z)
	} else if z == y && x <= z {
		fmt.Println("YES")
		fmt.Println(x, z, z)
	} else {
		fmt.Println("NO")
	}
}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var x, y, z int64
		fmt.Scanf("%d %d %d\n", &x, &y, &z)
		if x != y && x != z && y != z {
			fmt.Println("NO")
			continue
		}
		if x == y && z > x || (x == z && y > x) || (y == z && x > y) {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
		if x==y && x == z {
			fmt.Println(x, y, z)
			continue
		}
		if x == y {
			fmt.Println(x, z, z)
		} else if x == z {
			fmt.Println(x, y, y)
		} else  {
			fmt.Println(x, z, z)
		}
	}
}

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

package main

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

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < cases; i++ {
		var x, y, z int64
		line := readLine(reader)
		strs := strings.Split(string(line), " ")
		x, _ = strconv.ParseInt(strs[0], 10, 64)
		y, _ = strconv.ParseInt(strs[1], 10, 64)
		z, _ = strconv.ParseInt(strs[2], 10, 64)
		if x != y && x != z && y != z {
			fmt.Println("NO")
			continue
		}
		if x == y && z > x || (x == z && y > x) || (y == z && x > y) {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
		if x == y && x == z {
			fmt.Println(x, y, z)
			continue
		}
		if x == y {
			fmt.Println(x, z, z)
		} else if x == z {
			fmt.Println(y, x, y)
		} else {
			fmt.Println(x, z, z)
		}
	}
}

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

package main

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

func main() {
	var t uint16
	var x, y, z uint32
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &t)
	for i := uint16(0); i < t; i++ {
		fmt.Fscanf(in, "%d %d %d\n", &x, &y, &z)
		if x == y {
			if z <= x {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else if x == z {
			if y <= x {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else if y == z {
			if x <= y {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	var t uint16
	var x, y, z uint32
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &t)
	for i := uint16(0); i < t; i++ {
		fmt.Fscanf(in, "%d %d %d\n", &x, &y, &z)
		if x == y {
			if z <= x {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else if x == z {
			if y <= x {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		} else {
			// y == z
			if x <= y {
				fmt.Println("YES")
				fmt.Println(x, x, y)
			} else {
				fmt.Println("NO")
			}
		}
	}
}

package main

import "fmt"

func main() {
	var t, x, y, z int
	fmt.Scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		fmt.Scanf("%d %d %d\n", &x, &y, &z)
		cnt, max := 1, 0
		if x > max {
			max = x
			cnt = 1
		}
		if y > max {
			max = y
			cnt = 1
		} else if y == max {
			cnt = 2
		}

		if z > max {
			max = z
			cnt = 1
		} else if z == max {
			cnt++
		}

		if cnt == 1 {
			fmt.Println("NO")
		} else if cnt == 2 {
			fmt.Println("YES")
			fmt.Println(x, y, z)
		} else {
			fmt.Println("YES")
			if x != max {
				fmt.Println(x, x, max)
			} else if y != max {
				fmt.Println(y, max, y)
			} else {
				fmt.Println(max, z, z)
			}
		}
	}

}


package main

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

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

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

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func next(n int) int {
	for isPrime(n) == false {
		n++
	}
	return n
}
func main() {
	defer writer.Flush()

	var n int
	scanf("%d", &n)
	nxt := next(n)
	printf("%d\n", nxt)
	for i := 0; i < n; i++ {
		printf("%d %d\n", i+1, (i+1)%n+1)
	}
	p1 := 2
	p2 := n
	for i := 0; i < nxt-n; i++ {
		printf("%d %d\n", p1, p2)
		p1++
		p2--
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1178/D
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	n int

	A [][2]int
)

func main() {
	n = ReadInt()

	p := n
	for i := 0; ; i++ {
		if IsPrime(p) {
			break
		}
		p++
	}

	for i := 1; i <= n; i++ {
		var e [2]int
		if i == n {
			e = [2]int{n, 1}
		} else {
			e = [2]int{i, i + 1}
		}

		A = append(A, e)
	}

	nokori := p - n
	for i := 0; i < nokori; i++ {
		s := 1 + i
		t := s + n/2
		A = append(A, [2]int{s, t})
	}

	fmt.Println(len(A))
	for i := 0; i < len(A); i++ {
		fmt.Println(A[i][0], A[i][1])
	}
}

// IsPrime judges whether an argument integer is a prime number or not.
func IsPrime(n int) bool {
	if n == 1 {
		return false
	}

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}

	return true
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main
import "fmt"
func check(x int) bool{
	for i:=2;i*i<=x;i++{
		if x%i==0{
			return false
		}
	}
	return true
}
func main() {
	var n int
	fmt.Scanf("%d",&n)
	num:=0
	for i:=n;i<=2*n;i++{
		if check(i){
			num=i
			break
		}
	}
	fmt.Printf("%d\n",num)
	for i:=1;i<n;i++{
		fmt.Printf("%d %d\n",i,i+1)
	}
	fmt.Printf("%d 1\n",n)
	num=num-n
	for i:=1;i<=num;i++{
		fmt.Printf("%d %d\n",i,n-i)
	}
}


package main

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

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

	var n int
	fmt.Fscanln(in, &n)

	minIndex1 := 1
	var minColor1 int
	fmt.Fscan(in, &minColor1)

	minIndex2 := -1

	maxIndex1 := -1
	maxColor1 := 0

	maxIndex2 := -1

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

		if minIndex2 == -1 && color != minColor1  {
			minIndex2 = i
		}

		if color != maxColor1 {
			maxIndex2 = maxIndex1

			maxColor1 = color
		}
		maxIndex1 = i
	}

	if minColor1 != maxColor1 {
		fmt.Println(maxIndex1 - minIndex1)
	} else if maxIndex1 - minIndex2 > maxIndex2 - minIndex1 {
		fmt.Println(maxIndex1 - minIndex2)
	} else {
		fmt.Println(maxIndex2 - minIndex1)
	}
}

package main

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

const N = 300300
var n int
var a[N] int

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

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	var ret = 0
	for i := 1; i <= n; i++ {

		if a[i] != a[1] {
			ret = max(ret, i - 1)
		}

		if a[i] != a[n] {
			ret = max(ret, n - i)
		}
	}
	fmt.Fprintf(writer, "%d", ret)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	n := 0
	fmt.Fscan(in, &n)
	houseColor := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &houseColor[i])
	}
	for i := 1; i < n; i++ {
		if houseColor[0] != houseColor[n-i] {
			fmt.Println(n - i)
			break
		}
		if houseColor[n-1] != houseColor[i-1] {
			fmt.Println(n - i)
			break
		}
	}
}

package main

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

func main() {
	var n, cnt int
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n)
	M := make(map[int][]int)
	B := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(scr, "%d", &B[i])
		if i == 0 {
			M[B[i]] = append(M[B[i]], i)
		} else if i == n-1 {
			M[B[i]] = append(M[B[i]], i)
		}
	}

	if len(M) == 2 {
		fmt.Println(n - 1)
	} else {
		for i := 1; i < n-1; i++ {
			if B[i] != B[0] {
				cnt = M[B[0]][1] - i
				break
			}
		}
		for i := n - 2; i >= 1; i-- {
			if B[i] != B[0] {
				if cnt < (i - M[B[0]][0]) {
					cnt = M[B[0]][0] - i
					break
				}
			}
		}
		fmt.Println(math.Abs(float64(cnt)))
	}
}

package main

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

func main() {
	var n, cnt int
	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n)
	M := make(map[int][]int)
	B := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(scr, "%d", &B[i])
		if i == 0 {
			M[B[i]] = append(M[B[i]], i)
		} else if i == n-1 {
			M[B[i]] = append(M[B[i]], i)
		}
	}

	if len(M) == 2 {
		fmt.Println(n - 1)
	} else {
		for i := 1; i < n-1; i++ {
			if B[i] != B[0] {
				cnt = M[B[0]][1] - i
				break
			}
		}
		for i := n - 2; i >= 1; i-- {
			if B[i] != B[0] {
				if cnt < (i - M[B[0]][0]) {
					cnt = M[B[0]][0] - i
					break
				}
			}
		}
		fmt.Println(cnt)
	}
}

package main

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

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

	var n int
	fmt.Fscanln(in, &n)

	minIndex1 := 1
	var minColor1 int
	fmt.Fscan(in, &minColor1)

	minIndex2 := -1

	maxIndex1 := -1
	maxColor1 := 0

	maxIndex2 := -1
	maxColor2 := 0

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

		if minIndex2 == -1 && color != minColor1  {
			minIndex2 = i
		}

		if color != maxColor1 {
			maxIndex2 = maxIndex1
			maxColor2 = maxColor1

			maxColor1 = color
			maxIndex1 = i
		} else if color != maxColor2 {
			maxIndex2 = i
			maxColor2 = color
		}
	}

	if minColor1 != maxColor1 {
		fmt.Println(maxIndex1 - minIndex1)
	} else if maxIndex1 - minIndex2 > maxIndex2 - minIndex1 {
		fmt.Println(maxIndex1 - minIndex2)
	} else {
		fmt.Println(maxIndex2 - minIndex1)
	}
}