package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		v    int
		lock bool
	}
	f := func(a []int) int {
		ans, s := -1, 0
		for i, v := range a {
			s += v
			if s < 0 {
				ans = i
			}
		}
		return ans + 1
	}

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]pair, n)
		for i := range a {
			Fscan(in, &a[i].v)
		}
		var b, ans1, ans2 []int
		for i, p := range a {
			Fscan(in, &a[i].lock)
			if !a[i].lock {
				b = append(b, p.v)
			}
		}
		sort.Ints(b)
		l, r := 0, len(b)-1
		for _, p := range a {
			if p.lock {
				ans1 = append(ans1, p.v)
				ans2 = append(ans2, p.v)
			} else {
				ans1 = append(ans1, b[l])
				l++
				ans2 = append(ans2, b[r])
				r--
			}
		}
		if f(ans1) < f(ans2) {
			for _, v := range ans1 {
				Fprint(out, v, " ")
			}
		} else {
			for _, v := range ans2 {
				Fprint(out, v, " ")
			}
		}
		Fprintln(out)
	}
}

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

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	tt := rw.NextInt()
	for i := 0; i < tt; i++ {
		solveCase()
	}
}

func solveCase() {
	n := rw.NextInt()
	a := rw.NextInts(n)
	b := rw.NextInts(n)
	var c []int
	for i := 0; i < n; i++ {
		if b[i] == 0 {
			c = append(c, -a[i])
		}
	}
	sort.Ints(c)
	for i, j := 0, 0; i < n; i++ {
		if b[i] == 0 {
			a[i] = -c[j]
			j++
		}
	}
	rw.PrintlnInts(a...)
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

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

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

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

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

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

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

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

/*
5
3
1 3 2
0 0 0
4
2 -3 4 -1
1 1 1 1
7
-8 4 -2 -6 4 7 1
1 0 0 0 1 1 0
5
0 1 -4 6 3
0 0 0 1 1
6
-1 7 10 4 -8 -1
1 0 0 0 0 1

1 2 3
2 -3 4 -1
-8 -6 1 4 4 7 -2
-4 0 1 6 3
-1 4 7 -8 10 -1
*/

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

	var T, N, target int64
	for Fscan(in, &T); T > int64(0); T-- {
		var A []int64
		var AUnlock []int64
		var B []int64
		Fscan(in, &N)

		for i := 0; i < int(N); i++ {
			Fscan(in, &target)
			A = append(A, target)
		}

		for i := 0; i < int(N); i++ {
			Fscan(in, &target)
			B = append(B, target)
			if target == 0 {
				AUnlock = append(AUnlock, A[i])
			}
		}

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

		i, j := 0, 0
		for ; i < len(B); i++ {
			if B[i] == 1 {
				Fprintf(out, "%d ", A[i])
			}else {
				Fprintf(out, "%d ", AUnlock[j])
				j++
			}
		}
		Fprintf(out, "\n")
	}

}

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

package main

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

func solve(r *bufio.Reader, w *bufio.Writer) {
	var n int
	fmt.Fscanln(r, &n)
	a := make([]int, n)
	for i := 0; i < n-1; i++ {
		fmt.Fscanf(r, "%d ", &a[i])
	}
	fmt.Fscanf(r, "%d\n", &a[n-1])
	lock := make([]int, n)
	for i := 0; i < n-1; i++ {
		fmt.Fscanf(r, "%d ", &lock[i])
	}
	fmt.Fscanf(r, "%d\n", &lock[n-1])
	shouldSort := make([]int, 0, n)
	for i := 0; i < n; i++ {
		if lock[i] == 0 {
			shouldSort = append(shouldSort, a[i])
		}
	}
	sort.Ints(shouldSort)
	k := len(shouldSort) - 1
	for i := 0; i < n; i++ {
		if lock[i] == 1 {
			continue
		}
		a[i] = shouldSort[k]
		k -= 1
	}
	for i := 0; i < n-1; i++ {
		fmt.Fprintf(w, "%d ", a[i])
	}
	fmt.Fprintf(w, "%d\n", a[n-1])
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		solve(reader, writer)
	}
}

package main

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

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

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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 Gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return Gcd(b, a%b)
}

const mod = 1000000007

func Add(a, b int64) int64 {
	return (a + b) % mod
}

func Mult(a, b int64) int64 {
	return (a * b) % mod
}

func Sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

func solve() {
	// x, y, k := nextLong()-1, nextLong(), nextLong()
	// printf("%d\n", k+((y+1)*k+x-2)/x)
	n := nextInt()
	arr := make([]int, n)
	for i := range arr {
		arr[i] = nextInt()
	}
	lock := make([]int, n)
	tmp := []int{}
	for i, v := range arr {
		lock[i] = nextInt()
		if lock[i] == 0 {
			tmp = append(tmp, v)
		}
	}
	sort.Ints(tmp)
	ind := n - 1
	for _, v := range tmp {
		for lock[ind] == 1 {
			ind--
		}
		arr[ind] = v
		ind--
	}

	for _, v := range arr {
		printf("%d ", v)
	}
	printf("\n")
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "foreign"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create(name + ".out")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// 	printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		L := readNNums(reader, n)
		solve(n, A, L)
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", A[i]))
		}
		buf.WriteByte('\n')
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, A []int, L []int) {
	ps := make([]Pair, 0, n)
	for i := 0; i < n; i++ {
		if L[i] == 0 {
			ps = append(ps, Pair{A[i], i})
		}
	}

	sort.Sort(Pairs(ps))
	var j int
	for i := 0; i < n; i++ {
		if L[i] == 0 {
			A[i] = ps[j].first
			j++
		}
	}
}

type Pair struct {
	first, second int
}

type Pairs []Pair

func (ps Pairs) Len() int {
	return len(ps)
}

func (ps Pairs) Less(i, j int) bool {
	return ps[i].first > ps[j].first
}

func (ps Pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

package main

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

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 int
	var n int
	var arr []int
	var b []int
	var un []int

	var ans []int
	scanf("%d\n", &t)
	for t > 0 {
		scanf("%d\n", &n)
		arr = make([]int, n)
		b = make([]int, n)
		un = make([]int, 0)
		ans = make([]int, n)
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}
		scanf("\n")
		for i := 0; i < n; i++ {
			scanf("%d", &b[i])
			if b[i] == 0 {
				un = append(un, arr[i])
			}
		}
		scanf("\n")
		sort.Sort(sort.Reverse(sort.IntSlice(un)))
		// printf("%v\n", arr)
		// printf("%v\n", un)
		j := 0
		for i := 0; i < n || j < len(un); i++ {
			if b[i] == 1 {
				ans[i] = arr[i]
			} else {
				ans[i] = un[j]
				j++
			}
		}
		for _, v := range ans {
			printf("%v ", v)
		}
		printf("\n")
		t--
	}
}

/*
URL:
https://codeforces.com/contest/1418/problem/B
*/

package main

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

var (
	t int

	n int
	A []int
	L []int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		A = readis(n)
		L = readis(n)

		solve()
	}
}

func solve() {
	S := Sum(A...)

	if S < 0 {
		fmt.Println(PrintIntsLine(A...))
		return
	}

	B := []int{}
	for i := 0; i < n; i++ {
		if L[i] == 0 {
			B = append(B, A[i])
		}
	}

	sort.Sort(sort.Reverse(sort.IntSlice(B)))

	idx := 0
	for i := 0; i < n; i++ {
		if L[i] == 0 {
			A[i] = B[idx]
			idx++
		}
	}

	fmt.Println(PrintIntsLine(A...))
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
)

// modi can calculate a right residual whether value is positive or negative.
func modi(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// modll can calculate a right residual whether value is positive or negative.
func modll(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

/********** bufio setting **********/

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

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  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()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

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

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

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	tt := rw.NextInt()
	for i := 0; i < tt; i++ {
		solveCase()
	}
}
func solveCase() {
	n := rw.NextInt()
	a := rw.NextInts(n)
	b := rw.NextInts(n)
	c := make([]int, 0)
	for i, v := range a {
		if b[i] == 0 {
			c = append(c, -v)
		}
	}
	sort.Ints(c)
	j := 0
	for i := 0; i < len(a); i++ {
		if b[i] == 0 {
			a[i] = -c[j]
			j++
		}
	}
	rw.PrintlnInts(a...)
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

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

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

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

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

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

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

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		b := readIntArray(n)
		c := make([]int, 0)
		for i, v := range a {
			if b[i] == 0 {
				c = append(c, -v)
			}
		}
		sort.Ints(c)
		j := 0
		for i := 0; i < len(a); i++ {
			if b[i] == 0 {
				a[i] = -c[j]
				j++
			}
		}
		for i := 0; i < len(a); i++ {
			if i > 0 {
				fmt.Print(" ")
			}
			fmt.Print(a[i])
		}
		fmt.Println()
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func sort(a, b []int, n int) []int {
	var ind = 0
	for j := 0; j < n-1; j++ {
		for ;j < n-1; j++ {
			if b[j] == 0 {
				ind = j
				break
			}
		}
		for i := j+1; i < n; i++ {
			if a[i] > a[ind] && b[i] == 0{
				ind = i;
			}
		}
		if b[ind] + b[j] == 0 && a[ind] > a[j] && ind > j {
			a[ind], a[j] = a[j], a[ind]
		}
	}
	return a
}

func main() {
defer w.Flush()
	var q int
	scan(&q)
	for ; q > 0; q-- {
		var n int
		scan(&n)
		var a = make([]int, n)
		var b = make([]int, n)
		for i:=0; i< n; i++ {
			scan(&a[i])
		}
		for i:=0; i< n; i++ {
			scan(&b[i])
		}

		a = sort(a,b,n)
		for i:=0; i < n ; i++ {
			print(a[i], " ")
		}
		print("\n")
	}
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		n := readInt()
		a := readIntArray(n)
		b := readIntArray(n)
		c := make([]int, 0)
		for i, v := range a {
			if b[i] == 0 {
				c = append(c, v)
			}
		}
		sort.Ints(c)
		j := 0
		for i := 0; i < len(a); i++ {
			if b[i] == 0 {
				a[i] = c[j]
				j++
			}
		}
		for i := 0; i < len(a); i++ {
			if i > 0 {
				fmt.Print(" ")
			}
			fmt.Print(a[i])
		}
		fmt.Println()
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func sort(a, b []int, n int) []int {
	var ind = 0
	for j := 0; j < n-1; j++ {
		for ;j < n-1; j++ {
			if b[j] == 0 {
				ind = j
				break
			}
		}
		for i := j+1; i < n; i++ {
			if a[i] > a[ind] && b[i] == 0{
				ind = i;
			}
		}
		if b[ind] + b[j] == 0 && a[ind] > a[j] {
			a[ind], a[j] = a[j], a[ind]
		}
	}
	return a
}

func main() {
defer w.Flush()
	var q int
	scan(&q)
	for ; q > 0; q-- {
		var n int
		scan(&n)
		var a = make([]int, n)
		var b = make([]int, n)
		for i:=0; i< n; i++ {
			scan(&a[i])
		}
		for i:=0; i< n; i++ {
			scan(&b[i])
		}

		a = sort(a,b,n)
		for i:=0; i < n ; i++ {
			print(a[i], " ")
		}
		print("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func sort(a, b []int, n int) []int {
	var ind = 0
	for j := 0; j < n-1; j++ {
		for ;j < n-1; j++ {
			if b[j] == 0 {
				ind = j
				break
			}
		}
		for i := j+1; i < n; i++ {
			if a[i] > a[ind] && b[i] == 0{
				ind = i;
			}
		}
		if b[ind] + b[j] == 0 {
			a[ind], a[j] = a[j], a[ind]
		}
	}
	return a
}

func main() {
defer w.Flush()
	var q int
	scan(&q)
	for ; q > 0; q-- {
		var n int
		scan(&n)
		var a = make([]int, n)
		var b = make([]int, n)
		for i:=0; i< n; i++ {
			scan(&a[i])
		}
		for i:=0; i< n; i++ {
			scan(&b[i])
		}

		a = sort(a,b,n)
		for i:=0; i < n ; i++ {
			print(a[i], " ")
		}
		print("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func sort(a, b []int, n int) []int {
	var ind = -1
	var pind = ind
	for j := 0; j < n-1; j++ {
		for ;j < n-1; j++ {
			if b[j] == 0 {
				ind = j
				break
			}
		}
		if ind > pind {
			for i := j+1; i < n; i++ {
				if a[i] > a[ind] && b[i] == 0{
					ind = i;
				}
			}
			a[ind], a[j] = a[j], a[ind]
		}
		pind = ind
	}
	return a
}

func main() {
defer w.Flush()
	var q int
	scan(&q)
	for ; q > 0; q-- {
		var n int
		scan(&n)
		var a = make([]int, n)
		var b = make([]int, n)
		for i:=0; i< n; i++ {
			scan(&a[i])
		}
		for i:=0; i< n; i++ {
			scan(&b[i])
		}

		a = sort(a,b,n)
		for i:=0; i < n ; i++ {
			print(a[i], " ")
		}
		print("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func sort(a, b []int, n int) []int {
	var ind = -1
	var pind = ind
	for j := 0; j < n-1; j++ {
		for ;j < n-1; j++ {
			if b[j] == 0 {
				ind = j
				break
			}
		}
		if ind > pind {
			for i := j+1; i < n; i++ {
				if a[i] < a[ind] && b[i] == 0{
					ind = i;
				}
			}
			a[ind], a[j] = a[j], a[ind]
		}
		pind = ind
	}
	return a
}

func main() {
defer w.Flush()
	var q int
	scan(&q)
	for ; q > 0; q-- {
		var n int
		scan(&n)
		var a = make([]int, n)
		var b = make([]int, n)
		for i:=0; i< n; i++ {
			scan(&a[i])
		}
		for i:=0; i< n; i++ {
			scan(&b[i])
		}

		a = sort(a,b,n)
		for i:=0; i < n ; i++ {
			print(a[i], " ")
		}
		print("\n")
	}
}

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	tt := rw.NextInt()
	for i := 0; i < tt; i++ {
		solveCase()
	}
}

func solveCase() {
	n := rw.NextInt()
	a := rw.NextInts(n)
	b := rw.NextInts(n)
	var c []int
	for i := 0; i < n; i++ {
		if b[i] == 0 {
			c = append(c, -a[i])
		}
	}
	sort.Ints(c)
	for i, j := 0, 0; i < n; i++ {
		if b[i] == 0 {
			a[i] = c[j]
			j++
		}
	}
	rw.PrintlnInts(a...)
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

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

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

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

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

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

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

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

/*
5
3
1 3 2
0 0 0
4
2 -3 4 -1
1 1 1 1
7
-8 4 -2 -6 4 7 1
1 0 0 0 1 1 0
5
0 1 -4 6 3
0 0 0 1 1
6
-1 7 10 4 -8 -1
1 0 0 0 0 1

1 2 3
2 -3 4 -1
-8 -6 1 4 4 7 -2
-4 0 1 6 3
-1 4 7 -8 10 -1
*/

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

	var T, N, target int64
	var A []int64
	var AUnlock []int64
	var B []int64
	for Fscan(in, &T); T > int64(0); T-- {
		Fscan(in, &N)

		for i := 0; i < int(N); i++ {
			Fscan(in, &target)
			A = append(A, target)
		}

		for i := 0; i < int(N); i++ {
			Fscan(in, &target)
			B = append(B, target)
			if target == 0 {
				AUnlock = append(AUnlock, target)
			}
		}

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

		i, j := 0, 0
		for ; i < len(B); i++ {
			if B[i] == 1 {
				Fprintf(out, "%d ", A[i])
			}else {
				Fprintf(out, "%d ", AUnlock[j])
				j++
			}
		}
		Fprintf(out, "\n")
	}

}

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

package main

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

func solve(r *bufio.Reader, w *bufio.Writer) {
	var n int
	fmt.Fscanln(r, &n)
	a := make([]int, n)
	for i := 0; i < n-1; i++ {
		fmt.Fscanf(r, "%d ", &a[i])
	}
	fmt.Fscanf(r, "%d\n", &a[n-1])
	lock := make([]int, n)
	for i := 0; i < n-1; i++ {
		fmt.Fscanf(r, "%d ", &lock[i])
	}
	fmt.Fscanf(r, "%d\n", &lock[n-1])
	shouldSort := make([]int, 0, n)
	for i := 0; i < n; i++ {
		if lock[i] == 0 {
			shouldSort = append(shouldSort, a[i])
		}
	}
	sort.Ints(shouldSort)
	k := 0
	for i := 0; i < n; i++ {
		if lock[i] == 1 {
			continue
		}
		a[i] = shouldSort[k]
		k += 1
	}
	for i := 0; i < n-1; i++ {
		fmt.Fprintf(w, "%d ", a[i])
	}
	fmt.Fprintf(w, "%d\n", a[n-1])
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		solve(reader, writer)
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1147B(reader io.Reader, writer io.Writer) {
	calcMinPeriod := func(pattern []int) int {
		n := len(pattern)
		maxMatchLengths := make([]int, n)
		maxLength := 0
		for i := 1; i < n; i++ {
			c := pattern[i]
			for maxLength > 0 && pattern[maxLength] != c {
				maxLength = maxMatchLengths[maxLength-1]
			}
			if pattern[maxLength] == c {
				maxLength++
			}
			maxMatchLengths[i] = maxLength
		}
		if val := maxMatchLengths[n-1]; val > 0 {
			if n%(n-val) == 0 {
				return n / (n - val)
			}
		}
		return 0
	}
	calcGCD := func(a, b int64) int64 {
		for b > 0 {
			a, b = b, a%b
		}
		return a
	}
	calcLCM := func(a, b int64) int64 {
		return a / calcGCD(a, b) * b
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n, m int
	Fscan(in, &n, &m)
	lenPosMat := make([][]int, n/2+5)
	for ; m > 0; m-- {
		var a, b int
		Fscan(in, &a, &b)
		if a > b {
			a, b = b, a
		}
		segLen := b - a
		pos := a
		if segLen > n-segLen {
			segLen = n - segLen
			pos = b
		}
		lenPosMat[segLen] = append(lenPosMat[segLen], pos)
	}

	k := int64(-1)
	for segLen, posList := range lenPosMat {
		if len(posList) == 0 {
			continue
		}
		var p int
		if segLen*2 < n {
			sort.Ints(posList)
			posList = append(posList, posList[0]+n)
			diffList := make([]int, len(posList)-1)
			for i := range diffList {
				diffList[i] = posList[i+1] - posList[i]
			}
			p = calcMinPeriod(diffList)
			if p == 0 {
				Fprint(out, "No")
				return
			}
		} else if segLen*2 == n {
			p = 2
		} else {
			break
		}
		if n%p > 0 {
			Fprint(out, "No")
			return
		}
		p = n / p
		if k == -1 {
			k = int64(p)
		} else {
			k = calcLCM(k, int64(p))
		}
		if k >= int64(n) {
			Fprint(out, "No")
			return
		}
	}
	Fprint(out, "Yes")
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	segs := make([][]int, n+1)
	for i := 0; i < n; i++ {
		segs[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		l, r := 0, 0
		fmt.Fscanf(in, "%d %d\n", &l, &r)
		diff1 := ((r + n) - l) % n
		diff2 := ((l + n) - r) % n
		if diff2 > diff1 {
			segs[diff1] = append(segs[diff1], l)
		} else {
			segs[diff2] = append(segs[diff2], r)
		}
	}
	ans := n
	for i := 0; i < n+1; i++ {
		if len(segs[i]) == 1 && i != n/2 {
			fmt.Fprintf(out, "No\n")
			return
		}
	}
	for i := 0; i < n+1; i++ {
		if len(segs[i]) > 0 {
			q := findPattern(segs[i], n)
			if i == n/2 {
				if q < 2 {
					q = 2
				}
			}
			ans = gcd(ans, q)
			//fmt.Println(ans)
			if ans < 2 {
				fmt.Fprintf(out, "No\n")
				return
			}
		}
	}
	fmt.Fprintf(out, "Yes\n")
	return
}

func findPattern(a []int, m int) int {
	sort.Ints(a)
	for i := 1; i <= len(a)/2; i++ {
		if len(a)%i == 0 {
			if work(a, i, m) {
				return len(a) / i
			}
		}
	}
	return 1
}

func work(a []int, l int, m int) bool {
	//fmt.Println(a, l, m)
	n := len(a)
	numOfSeg := n / l
	for i := 1; i < numOfSeg; i++ {
		if a[i*l]-a[(i-1)*l] != (a[0] + m - a[(numOfSeg-1)*l]) {
			//fmt.Println(a, l, "debug")
			return false
		}
	}
	for j := 1; j < l; j++ {
		for i := 1; i < n/l; i++ {
			if a[i*l+j]-a[i*l+j-1] != a[j]-a[j-1] {
				//fmt.Println(a, l, "debug2")
				return false
			}
		}
	}
	return true
}

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

package main

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

type Integers2 []int

func (s Integers2) Len() int {
	return len(s)
}
func (s Integers2) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s Integers2) Less(i, j int) bool {
	return s[i] < s[j]
}

func Newton(a []int, x int) int {
	n2 := len(a) - 1
	if n2 == -1 {
		return -1
	}
	n1 := 0
	var n int
	if x < a[n1] || x > a[n2] {
		return -1
	}
	if x == a[n1] {
		return n1
	}
	if x == a[n2] {
		return n2
	}
	for {
		if n2-n1 < 3 {
			for i := n1 + 1; i < n2; i++ {
				if x == a[i] {
					return i
				}
			}
			return -1
		}
		n = (n1 + n2) / 2
		if x == a[n] {
			return n
		}
		if x > a[n] {
			n1 = n
		} else {
			n2 = n
		}

	}
}

func main() {
	read := bufio.NewReader(os.Stdin)
	write := bufio.NewWriter(os.Stdout)

	var n, m int
	fmt.Fscan(read, &n, &m)
	ti := make([]bool, n)
	thord := make([][]int, n)
	ver := make([]int, 2*m)
	a := make([][2]int, m)

	var i int
	for i = 0; i < m; i++ {
		var x, y int
		fmt.Fscan(read, &x, &y)
		var h [2]int

		if x < y {
			h = [2]int{x, y}
		} else {
			h = [2]int{y, x}
		}

		a[i] = h
		ti[x-1] = true
		ti[y-1] = true
		thord[h[0]-1] = append(thord[h[0]-1], h[1])
		ver[2*i] = x
		ver[2*i+1] = y
	}

	//sort.Sort(Integers2(a))
	for i = 0; i < m; i++ {
		sort.Sort(Integers2(thord[a[i][0]-1]))
	}

	sort.Sort(Integers2(ver))
	//resb := false
	res := "NO"
	//var i int32
	startx := ver[0]

	//nrutin := 0
	//intCh := make(chan int, nx) //Канал
	ver2 := make([]int, n)
	tx := -1
	nx := 0
	for _, val := range ver {
		if val == tx {
			continue
		}
		ver2[nx] = val
		tx = val
		nx++
	}

	nx2 := nx/2 + 1

	for i := 1; i < nx2; i++ {
		/*
			if resb {
				break
			}
		*/
		/*
			if ver[i] == tx {
				continue
			}
		*/
		tx = ver2[i]
		h := tx - startx

		//nrutin++
		//go func(h int) {
		r := true
		var j int
		for j = 0; j < m; j++ {
			/*
				if resb {
					intCh <- 5
					return
				}
			*/

			x := a[j][0] + h
			if x > n {
				x = x - n
			}
			y := a[j][1] + h
			if y > n {
				y = y - n
			}

			if !ti[x-1] || !ti[y-1] {
				r = false
				break
			}

			amin := x
			amax := y
			if amax < amin {
				amax = x
				amin = y
			}

			ch := Newton(thord[amin-1], amax)

			if ch == -1 {
				r = false
				break
			}

		}

		if r {
			//resb = true
			res = "YES"
			break
		}
		//intCh <- 5
		//}(hh)
	}
	/*
		for i := 0; i < nrutin; i++ {
			_ = <-intCh

		}
	*/
	fmt.Fprint(write, res)
	write.Flush()

}

package main

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

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

func map_equals(a, b map[int]bool) bool {
	for k, v := range a {
		val, ok := b[k]
		if ok == false || val != v {
			return false
		}
	}
	return true
}

func z_algorithm(vals []map[int]bool) []int {
	z := make([]int, len(vals))
	var left, right int
	for i := 1; i < len(vals); i++ {
		if i <= right {
			z[i] = min(z[i-left], right-i+1)
		}
		for i+z[i] < len(vals) && map_equals(vals[z[i]], vals[i+z[i]]) {
			z[i]++
		}
		if i+z[i]-1 > right {
			left = i
			right = i + z[i] - 1
		}
	}
	return z
}

func main() {

	var reader *bufio.Reader = bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	vals := make([]map[int]bool, n)
	for i := 0; i < n; i++ {
		vals[i] = make(map[int]bool)
	}
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Fscanf(reader, "%d %d\n", &a, &b)
		a--
		b--
		vals[a][(a-b+n)%n] = true
		vals[b][(b-a+n)%n] = true
	}
	for i := 0; i < n; i++ {
		vals = append(vals, vals[i])
	}
	z := z_algorithm(vals)
	//fmt.Printf("%v ", z)
	var res bool
	for i := 0; i < 2*n; i++ {
		if i != n && z[i] >= n {
			res = true
		}
	}
	if res {
		fmt.Print("Yes\n")
	} else {
		fmt.Print("No\n")
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1147B(reader io.Reader, writer io.Writer) {
	calcMinPeriod := func(pattern []int) int {
		n := len(pattern)
		maxMatchLengths := make([]int, n)
		maxLength := 0
		for i := 1; i < n; i++ {
			c := pattern[i]
			for maxLength > 0 && pattern[maxLength] != c {
				maxLength = maxMatchLengths[maxLength-1]
			}
			if pattern[maxLength] == c {
				maxLength++
			}
			maxMatchLengths[i] = maxLength
		}
		if val := maxMatchLengths[n-1]; val > 0 {
			if n%(n-val) == 0 {
				return n / (n - val)
			}
		}
		return 0
	}
	calcGCD := func(a, b int64) int64 {
		for b > 0 {
			a, b = b, a%b
		}
		return a
	}
	calcLCM := func(a, b int64) int64 {
		return a / calcGCD(a, b) * b
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n, m int
	Fscan(in, &n, &m)
	lenPosMat := make([][]int, n/2+1)
	for ; m > 0; m-- {
		var a, b int
		Fscan(in, &a, &b)
		if a > b {
			a, b = b, a
		}
		segLen := b - a
		pos := a
		if segLen > n-segLen {
			segLen = n - segLen
			pos = b
		}
		lenPosMat[segLen] = append(lenPosMat[segLen], pos)
	}

	k := int64(-1)
	for segLen, posList := range lenPosMat {
		if len(posList) == 0 {
			continue
		}
		var p int
		if segLen*2 < n {
			sort.Ints(posList)
			posList = append(posList, posList[0]+n)
			diffList := make([]int, len(posList)-1)
			for i := range diffList {
				diffList[i] = posList[i+1] - posList[i]
			}
			p = calcMinPeriod(diffList)
			if p == 0 {
				Fprint(out, "No")
				return
			}
		} else if segLen*2 == n {
			p = 2
		} else {
			break
		}
		if n%p > 0 {
			Fprint(out, "No")
			return
		}
		p = n / p
		if k == -1 {
			k = int64(p)
		} else {
			k = calcLCM(k, int64(p))
		}
		if k >= int64(n) {
			Fprint(out, "No")
			return
		}
	}
	Fprint(out, "Yes")
}

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

package main

import "fmt"

/*
type Integers []int

func (s Integers) Len() int {
	return len(s)
}
func (s Integers) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s Integers) Less(i, j int) bool {
	return s[i] < s[j]
}
*/

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var ti = make([]int, n+1)
	var a []int
	for i := 0; i < m; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		a = append(a, x)
		a = append(a, y)
		ti[x] = 1
		ti[y] = 1
	}

	//sort.Sort(Integers(a))

	m = m * 2
	res := "NO"
	for i := 1; i < n; i++ {
		b := make([]int, m)
		copy(b, a)
		r := true
		for j := 0; j < m; j++ {
			b[j] = b[j] + i
			if b[j] > n {
				b[j] = b[j] - n
			}
			if ti[b[j]] != 1 {
				r = false
				break
			}
		}

		if r {
			res = "YES"
			break
		}
	}
	fmt.Print(res)
}

package main

import "fmt"

/*
type Integers []int

func (s Integers) Len() int {
	return len(s)
}
func (s Integers) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s Integers) Less(i, j int) bool {
	return s[i] < s[j]
}
*/

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var ti = make([]bool, n+1)
	/*
		var thord [][]bool
		for i := 0; i <= n; i++ {
			line := make([]bool, n+1)
			thord = append(thord, line)
		}
	*/

	var a [][]int
	for i := 0; i < m; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		h := []int{x, y}
		a = append(a, h)
		ti[x] = true
		ti[y] = true
	}

	//sort.Sort(Integers(a))

	res := "NO"
	for i := 1; i < n; i++ {

		r := true
		for j := 0; j < m; j++ {
			x := a[j][0] + i
			if x > n {
				x = x - n
			}
			y := a[j][1] + i
			if y > n {
				y = y - n
			}
			if !ti[x] || !ti[y] {
				r = false
				break
			}
			for k := 0; k < m; k++ {
				if (a[k][0] == x && a[k][1] == y) ||
					(a[k][0] == y && a[k][1] == x) {
					break
				}

			}

		}

		if r {
			res = "YES"
			break
		}
	}
	fmt.Print(res)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1147B(reader io.Reader, writer io.Writer) {
	calcMinPeriod := func(pattern []int) int {
		n := len(pattern)
		maxMatchLengths := make([]int, n)
		maxLength := 0
		for i := 1; i < n; i++ {
			c := pattern[i]
			for maxLength > 0 && pattern[maxLength] != c {
				maxLength = maxMatchLengths[maxLength-1]
			}
			if pattern[maxLength] == c {
				maxLength++
			}
			maxMatchLengths[i] = maxLength
		}
		if val := maxMatchLengths[n-1]; val > 0 {
			if n%(n-val) == 0 {
				return n / (n - val)
			}
		}
		return 0
	}
	calcGCD := func(a, b int64) int64 {
		for b > 0 {
			a, b = b, a%b
		}
		return a
	}
	calcLCM := func(a, b int64) int64 {
		return a / calcGCD(a, b) * b
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n, m int
	Fscan(in, &n, &m)
	lenPosMat := make([][]int, n/2+5)
	for ; m > 0; m-- {
		var a, b int
		Fscan(in, &a, &b)
		if a > b {
			a, b = b, a
		}
		segLen := b - a
		pos := a
		if segLen > n-segLen {
			segLen = n - segLen
			pos = b
		}
		lenPosMat[segLen] = append(lenPosMat[segLen], pos)
	}

	k := int64(-1)
	for segLen, posList := range lenPosMat {
		if len(posList) == 0 {
			continue
		}
		var p int64
		if segLen*2 < n {
			sort.Ints(posList)
			posList = append(posList, posList[0]+n)
			diffList := make([]int, len(posList)-1)
			for i := range diffList {
				diffList[i] = posList[i+1] - posList[i] - segLen
			}
			p = int64(calcMinPeriod(diffList))
			if p == 0 {
				Fprint(out, "No")
				return
			}
		} else if segLen*2 == n {
			p = int64(segLen)
		} else {
			break
		}
		if k == -1 {
			k = p
		} else {
			k = calcLCM(k, p)
		}
		if k >= int64(n) {
			Fprint(out, "No")
			return
		}
	}
	Fprint(out, "Yes")
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1147B(reader io.Reader, writer io.Writer) {
	calcMinPeriod := func(pattern []int) int {
		n := len(pattern)
		maxMatchLengths := make([]int, n)
		maxLength := 0
		for i := 1; i < n; i++ {
			c := pattern[i]
			for maxLength > 0 && pattern[maxLength] != c {
				maxLength = maxMatchLengths[maxLength-1]
			}
			if pattern[maxLength] == c {
				maxLength++
			}
			maxMatchLengths[i] = maxLength
		}
		if val := maxMatchLengths[n-1]; val > 0 {
			if val%(n-val) == 0 {
				return val/(n-val) + 1
			}
		}
		return 0
	}
	calcGCD := func(a, b int64) int64 {
		for b > 0 {
			a, b = b, a%b
		}
		return a
	}
	calcLCM := func(a, b int64) int64 {
		return a / calcGCD(a, b) * b
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n, m int
	Fscan(in, &n, &m)
	lenPosMat := make([][]int, n/2+1)
	for ; m > 0; m-- {
		var a, b int
		Fscan(in, &a, &b)
		if a > b {
			a, b = b, a
		}
		segLen := b - a
		pos := a
		if segLen > n-segLen {
			segLen = n - segLen
			pos = b
		}
		lenPosMat[segLen] = append(lenPosMat[segLen], pos)
	}

	k := int64(-1)
	for segLen, posList := range lenPosMat {
		if len(posList) == 0 {
			continue
		}
		var p int64
		if segLen*2 < n {
			sort.Ints(posList)
			posList = append(posList, posList[0]+n)
			diffList := make([]int, len(posList)-1)
			for i := range diffList {
				diffList[i] = posList[i+1] - posList[i] - segLen
			}
			p = int64(calcMinPeriod(diffList))
			if p == 0 {
				Fprint(out, "No")
				return
			}
		} else if segLen*2 == n {
			p = int64(segLen)
		} else {
			break
		}
		if k == -1 {
			k = p
		} else {
			k = calcLCM(k, p)
		}
		if k >= int64(n) {
			Fprint(out, "No")
			return
		}
	}
	Fprint(out, "Yes")
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	segs := make([][]int, n+1)
	for i := 0; i < n; i++ {
		segs[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		l, r := 0, 0
		fmt.Fscanf(in, "%d %d\n", &l, &r)
		diff := ((r + n) - l) % n
		segs[diff] = append(segs[diff], l)
	}
	ans := n
	for i := 0; i < n+1; i++ {
		if len(segs[i]) == 1 {
			fmt.Fprintf(out, "No\n")
			return
		}
	}
	for i := 0; i < n+1; i++ {
		if len(segs[i]) > 0 {
			q := findPattern(segs[i], n)
			if i == n/2 {
				if q < 2 {
					q = 2
				}
			}
			ans = gcd(ans, q)
			//fmt.Println(ans)
			if ans < 2 {
				fmt.Fprintf(out, "No\n")
				return
			}
		}
	}
	fmt.Fprintf(out, "Yes\n")
	return
}

func findPattern(a []int, m int) int {
	sort.Ints(a)
	for i := 1; i <= len(a)/2; i++ {
		if len(a)%i == 0 {
			if work(a, i, m) {
				return len(a) / i
			}
		}
	}
	return 1
}

func work(a []int, l int, m int) bool {
	//fmt.Println(a, l, m)
	n := len(a)
	numOfSeg := n / l
	for i := 1; i < numOfSeg; i++ {
		if a[i*l]-a[(i-1)*l] != (a[0] + m - a[(numOfSeg-1)*l]) {
			//fmt.Println(a, l, "debug")
			return false
		}
	}
	for j := 1; j < l; j++ {
		for i := 1; i < n/l; i++ {
			if a[i*l+j]-a[i*l+j-1] != a[j]-a[j-1] {
				//fmt.Println(a, l, "debug2")
				return false
			}
		}
	}
	return true
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	segs := make([][]int, n+1)
	for i := 0; i < n; i++ {
		segs[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		l, r := 0, 0
		fmt.Fscanf(in, "%d %d\n", &l, &r)
		diff1 := ((r + n) - l) % n
		diff2 := ((l + n) - r) % n
		if diff2 > diff1 {
			segs[diff1] = append(segs[diff1], l)
		} else {
			segs[diff2] = append(segs[diff2], r)
		}
	}
	ans := n
	for i := 0; i < n+1; i++ {
		if len(segs[i]) == 1 {
			fmt.Fprintf(out, "No\n")
			return
		}
	}
	for i := 0; i < n+1; i++ {
		if len(segs[i]) > 0 {
			q := findPattern(segs[i], n)
			if i == n/2 {
				if q < 2 {
					q = 2
				}
			}
			ans = gcd(ans, q)
			//fmt.Println(ans)
			if ans < 2 {
				fmt.Fprintf(out, "No\n")
				return
			}
		}
	}
	fmt.Fprintf(out, "Yes\n")
	return
}

func findPattern(a []int, m int) int {
	sort.Ints(a)
	for i := 1; i <= len(a)/2; i++ {
		if len(a)%i == 0 {
			if work(a, i, m) {
				return len(a) / i
			}
		}
	}
	return 1
}

func work(a []int, l int, m int) bool {
	//fmt.Println(a, l, m)
	n := len(a)
	numOfSeg := n / l
	for i := 1; i < numOfSeg; i++ {
		if a[i*l]-a[(i-1)*l] != (a[0] + m - a[(numOfSeg-1)*l]) {
			//fmt.Println(a, l, "debug")
			return false
		}
	}
	for j := 1; j < l; j++ {
		for i := 1; i < n/l; i++ {
			if a[i*l+j]-a[i*l+j-1] != a[j]-a[j-1] {
				//fmt.Println(a, l, "debug2")
				return false
			}
		}
	}
	return true
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	segs := make([][]int, n+1)
	for i := 0; i < n; i++ {
		segs[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		l, r := 0, 0
		fmt.Fscanf(in, "%d %d\n", &l, &r)
		diff := ((r + n) - l) % n
		segs[diff] = append(segs[diff], l)
	}
	ans := n
	for i := 0; i < n+1; i++ {
		if len(segs[i]) == 1 {
			fmt.Fprintf(out, "No\n")
			return
		}
	}
	for i := 0; i < n+1; i++ {
		if len(segs[i]) > 0 {
			q := findPattern(segs[i])
			ans = gcd(ans, q)
			if n < 2 {
				fmt.Fprintf(out, "No\n")
				return
			}
		}
	}
	fmt.Fprintf(out, "Yes\n")
	return
}

func findPattern(a []int) int {
	sort.Ints(a)
	for i := 1; i <= len(a)/2; i++ {
		if len(a)%i == 0 {
			if work(a, i) {
				return i
			}
		}
	}
	return 1
}

func work(a []int, l int) bool {
	n := len(a)
	for j := 1; j < l; j++ {
		for i := 1; i < n/l; i++ {
			if a[i*l+j]-a[i*l+j-1] != a[j]-a[j-1] {
				return false
			}
		}
	}
	return true
}

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


package main

import (
	"fmt"
	"bytes"
	"os"
	"io/ioutil"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int
	fmt.Fscanf(reader,"%d\n", &n)
	pos := make([]int, n)
	dist := make([]int, n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%d %d\n", &pos[i], &dist[i])
		for j := 0;j < i;j ++ {
			if pos[j] + dist[j] == pos[i] && pos[i] + dist[i] == pos[j] {
				fmt.Printf("YES")
				return
			}
		}
	}
	fmt.Printf("NO")
}

package main

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

var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func main() {
	defer w.Flush()

	var n int
	fmt.Fscanf(r, "%d\n", &n)
	m := make(map[int]int)
	var x, d int
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d %d\n", &x, &d)
		m[x] = d
	}

	for k, v := range m {
		if m[k+v] + k + v == k {
			fmt.Fprintf(w, "YES")
			return
		}
	}
	fmt.Fprintf(w, "NO")
}

package main

import "fmt"

const maxn = 102

func main() {
	var n int

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

	pos := make([]int, maxn)
	d := make([]int, maxn)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &pos[i], &d[i])
	}

	flag := false
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			if pos[i]+d[i] == pos[j] && d[i] == -d[j] {
				flag = true
				break
			}
		}

		if flag {
			break
		}
	}

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