You are given a grid with $$$n$$$ rows and $$$m$$$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $$$1 \le i \le n$$$ and $$$2 \le j \le m$$$ the following holds: $$$a_{i,j} \ge a_{i, j-1}$$$.You have to to do the following operation exactly once: choose two columns with indexes $$$i$$$ and $$$j$$$ (not necessarily different), $$$1 \le i, j \le m$$$, and swap them.You are asked to determine whether it is possible to make the grid good after the swap and, if it is, find the columns that need to be swapped.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the number of rows and columns respectively. Each of the next $$$n$$$ rows contains $$$m$$$ integers, $$$j$$$-th element of $$$i$$$-th row is $$$a_{i,j}$$$ ($$$1 \le a_{i,j} \le 10^9$$$) — the number written in the $$$j$$$-th cell of the $$$i$$$-th row. It's guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

If after the swap it is impossible to get a good grid, output $$$-1$$$. In the other case output $$$2$$$ integers — the indices of the columns that should be swapped to get a good grid. If there are multiple solutions, print any.

NoteIn the first test case the grid is initially good, so we can, for example, swap the first column with itself.In the second test case it is impossible to make the grid good.In the third test case it is needed to swap the first and the second column, then the grid becomes good.

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, m int
		Fscan(in, &n, &m)

		a := MakeGrid(n, m)
		mp := make(map[int]bool)
		keys := []int{0, 0}

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &a[i][j])
			}
			b := make([]int, m)
			copy(b, a[i])
			sort.Ints(b)
			for j := 0; j < m; j++ {
				if a[i][j] != b[j] {
					mp[j] = true
				}
			}
		}

		if len(mp) == 2 {
			jj := 0
			for k := range mp {
				keys[jj] = k
				jj++
			}
			sort.Ints(keys)

			flag := true
			for i := 0; i < n && m > 1; i++ {
				a[i][keys[0]], a[i][keys[1]] = a[i][keys[1]], a[i][keys[0]]
				for j := 1; j < m; j++ {
					if a[i][j] < a[i][j-1] {
						flag = false
						break
					}
				}
			}
			if flag {
				Fprintln(out, keys[0]+1, keys[1]+1)
			} else {
				Fprintln(out, -1)
			}
		} else if len(mp) == 0 {
			Fprintln(out, 1, 1)
		} else {
			Fprintln(out, -1)
		}

	}

}

func MakeGrid(h, w int) [][]int {
	index := make([][]int, h)
	data := make([]int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
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 tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N,M := gi(),gi(); A := make([][]int,N); for i:=0;i<N;i++ { A[i] = gis(M) }
		done := false; working := make([]int,M); badcols := make([]int,0)
		for i:=0;i<N;i++ {
			row := A[i]; copy(working,row); sort.Slice(working,func(i,j int) bool { return working[i] < working[j] } )
			for i:=0;i<M;i++ { if working[i] != row[i] { badcols = append(badcols,i) } }
			if len(badcols) == 0 { continue }
			if len(badcols) > 2 { fmt.Fprintln(wrtr,-1); done = true; break }
			good := true; c1,c2 := badcols[0],badcols[1]
			for ii:=0;ii<N;ii++ {
				row := A[ii]; row[c1],row[c2] = row[c2],row[c1]
				for i:=0;i<M-1;i++ { if row[i] > row[i+1] { good = false; break } }
			}
			if !good { fmt.Fprintln(wrtr,-1); } else { fmt.Fprintf(wrtr,"%v %v\n",c1+1,c2+1) }
			done = true; break
		}
		if !done { fmt.Fprintln(wrtr,"1 1") }
	}
}

package main

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

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

	var T, n, m int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		k := -1
		a := make([][]int, n)
		for i := range a {
			a[i] = make([]int, m)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
			if !sort.IntsAreSorted(a[i]) {
				k = i
			}
		}
		if k < 0 {
			Fprintln(out, 1, 1)
			continue
		}
		b := append([]int{}, a[k]...)
		sort.Ints(b)
		ps := []int{}
		for j, v := range a[k] {
			if v != b[j] {
				if len(ps) == 2 {
					Fprintln(out, -1)
					continue o
				}
				ps = append(ps, j)
			}
		}
		i, j := ps[0], ps[1]
		for _, r := range a {
			r[i], r[j] = r[j], r[i]
			if !sort.IntsAreSorted(r) {
				Fprintln(out, -1)
				continue o
			}
		}
		Fprintln(out, i+1, j+1)
	}
}

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

package main

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

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

	var T, n, m int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		k := -1
		a := make([][]int, n)
		for i := range a {
			a[i] = make([]int, m)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
			if !sort.IntsAreSorted(a[i]) {
				k = i
			}
		}
		if k < 0 {
			Fprintln(out, 1, 1)
			continue
		}
		ps := []int{}
		for j := 1; j < m; j++ {
			if a[k][j-1] > a[k][j] {
				if len(ps) == 2 {
					Fprintln(out, -1)
					continue o
				}
				ps = append(ps, j)
			}
		}
		var i, j int
		if len(ps) == 1 {
			j = ps[0]
			i = sort.SearchInts(a[k][:j], a[k][j]+1)
			for _, r := range a {
				r[i], r[j] = r[j], r[i]
				if !sort.IntsAreSorted(r) {
					r[i], r[j] = r[j], r[i]
					goto next
				}
				r[i], r[j] = r[j], r[i]
			}
			Fprintln(out, i+1, j+1)
			continue
		next:
			i = ps[0] - 1
			j = i + sort.SearchInts(a[k][i+1:], a[k][i])
		} else {
			i, j = ps[0]-1, ps[1]
		}
		for _, r := range a {
			r[i], r[j] = r[j], r[i]
			if !sort.IntsAreSorted(r) {
				Fprintln(out, -1)
				continue o
			}
		}
		Fprintln(out, i+1, j+1)
	}
}

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

package main

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

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, m int
		Fscan(in, &n, &m)
		grid := make([][]int, n)
		for i := 0; i < n; i++ {
			grid[i] = make([]int, m)
		}
		var fi = -1
		var se = -1
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &grid[i][j])
			}
		}
		var get bool
		var cnt int
		var row = []int{}
		for i := 0; i < n; i++ {
			col := make([]int, m)
			for k := 0; k < m; k++ {
				col[k] = grid[i][k]
			}
			sort.Ints(col)
			pos := []int{}
			for j := 0; j < m; j++ {
				if grid[i][j] != col[j] {
					pos = append(pos, j+1)
				}
			}
			if len(pos) > 2 {
				Fprintln(out, -1)
				return
			}
			//Fprintln(out, "---", pos)
			if len(pos) == 2 {
				cnt++
				if !get {
					fi = pos[0]
					se = pos[1]
					get = true
				} else {
					if fi != pos[0] || se != pos[1] {
						Fprintln(out, -1)
						return
					}
				}
			}
			if len(pos) == 0 {
				row = append(row, i)
			}
		}
		if !get {
			Fprintln(out, 1, 1)
		} else {
			for i := 0; i < len(row); i++ {
				if grid[row[i]][fi-1] == grid[row[i]][se-1] {
					cnt++
				}
			}
			if cnt < n {
				Fprintln(out, -1)
				return
			}
			Fprintln(out, fi, se)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }

package main

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

func solve(arr [][]int) (int, int, bool) {
	m := len(arr[0])
	c := make([]int, m)
	b := []int{}
	for i, v := range arr {
		copy(c, arr[i])
		sort.Ints(c)
		for j := 0; j < m; j++ {
			if c[j] != v[j] {
				b = append(b, j)
			}
			if len(b) > 2 {
				return -1, -1, false
			}
		}
		if len(b) == 2 {
			break
		}
	}
	if len(b) == 0 {
		return 0, 0, true
	}
	x, y := b[0], b[1]
	for _, v := range arr {
		v[x], v[y] = v[y], v[x]
		if !sort.IntsAreSorted(v) {
			return -1, -1, false
		}
	}
	return x, y, true
}
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		arr := make([][]int, n)
		for i := range arr {
			arr[i] = make([]int, m)
			for k := 0; k < m; k++ {
				Fscan(in, &arr[i][k])
			}
		}
		// fmt.Println(arr)
		x, y, f := solve(arr)
		if !f {
			Fprintln(out, "-1")
		} else {
			Fprintf(out, "%d %d\n", x+1, y+1)
		}
	}
}

func main() {
	run(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()

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

		g := make([]int, m)
		a := make(map[int][]int, n)
		for i := 0; i < n; i++ {
			b := make([]int, m)
			for j := 0; j < m; j++ {
				fmt.Fscan(in, &b[j])
			}
			a[i] = b

			c := make([]int, m)
			copy(c, b)
			sort.Ints(c)
			for k := range b {
				if b[k] == c[k] {
					continue
				}
				g[k]++
			}
		}

		x, y := -1, -1
		f := true
		for i, v := range g {
			if v != 0 {
				if x < 0 {
					x = i
				} else if y < 0 {
					y = i
				} else {
					f = false
					break
				}
			}
		}

		if !f {
			fmt.Fprintln(out, -1)
		} else if x < 0 {
			fmt.Fprintln(out, 1, 1)
		} else {
		Loop:
			for _, row := range a {
				row[x], row[y] = row[y], row[x]
				for j := 1; j < m; j++ {
					if row[j] < row[j-1] {
						f = false
						break Loop
					}
				}
			}

			if !f {
				fmt.Fprintln(out, -1)
			} else {
				fmt.Fprintln(out, x+1, y+1)
			}
		}
	}
}

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, m int
		Fscan(in, &n, &m)

		a := MakeGrid(n, m)
		mp := make(map[int]bool)
		keys := []int{1, 1}

		swopped := false

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &a[i][j])
			}
		}
		for i := 0; i < n; i++ {
			if !swopped {
				swopped = true
				b := make([]int, m)
				copy(b, a[i])
				sort.Ints(b)
				for j := 0; j < m; j++ {
					if a[i][j] != b[j] {
						mp[j] = true
					}
				}
				if len(mp) > 0 {
					keys = make([]int, len(mp))
					j := 0
					for k := range mp {
						keys[j] = k
						j++
					}
					sort.Ints(keys)
					if len(mp) > 2 {
						break
					}
				}
			} else if m > 1 {
				a[i][keys[0]], a[i][keys[1]] = a[i][keys[1]], a[i][keys[0]]
				for j := 1; j < m; j++ {
					if a[i][j] < a[i][j-1] {
						mp[-1] = true
						break
					}

				}
			}
		}
		if len(mp) == 0 {
			Fprintln(out, 1, 1)
		} else if len(mp) == 2 && !mp[-1] {
			Fprintln(out, keys[0]+1, keys[1]+1)
		} else {
			Fprintln(out, -1)
		}

	}

}

func MakeGrid(h, w int) [][]int {
	index := make([][]int, h)
	data := make([]int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, m int
		Fscan(in, &n, &m)

		a := MakeGrid(n, m)
		mp := make(map[int]bool)
		var keys []int

		swopped := false

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &a[i][j])
			}
		}
		for i := 0; i < n; i++ {
			if !swopped {
				b := make([]int, m)
				copy(b, a[i])
				sort.Ints(b)
				for j := 0; j < m; j++ {
					if a[i][j] != b[j] {
						mp[j] = true
					}
				}
				if len(mp) > 0 {
					swopped = true
					keys = make([]int, len(mp))
					j := 0
					for k := range mp {
						keys[j] = k
						j++
					}
					sort.Ints(keys)
					if len(mp) > 2 {
						break
					}
				}
			} else {
				a[i][keys[0]], a[i][keys[1]] = a[i][keys[1]], a[i][keys[0]]
				for j := 1; j < m; j++ {
					if a[i][j] < a[i][j-1] {
						mp[-1] = true
						break
					}

				}
			}
		}
		if len(mp) == 0 {
			Fprintln(out, 1, 1)
		} else if len(mp) == 2 && !mp[-1] {
			Fprintln(out, keys[0]+1, keys[1]+1)
		} else {
			Fprintln(out, -1)
		}

	}

}

func MakeGrid(h, w int) [][]int {
	index := make([][]int, h)
	data := make([]int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, m int
		Fscan(in, &n, &m)

		a := MakeGrid(n, m)
		mp := make(map[int]bool)
		var keys []int

		swopped := false

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &a[i][j])
			}
		}
		for i := 0; i < n; i++ {
			if !swopped {
				b := make([]int, m)
				copy(b, a[i])
				sort.Ints(b)
				for j := 0; j < m; j++ {
					if a[i][j] != b[j] {
						mp[j] = true
					}
				}
				if len(mp) > 0 {
					keys = make([]int, len(mp))
					swopped = true
					j := 0
					for k := range mp {
						keys[j] = k
						j++
					}
					sort.Ints(keys)
					if len(mp) > 2 {
						break
					}
				}
			} else {
				a[i][keys[0]], a[i][keys[1]] = a[i][keys[1]], a[i][keys[0]]
				for j := 1; j < m; j++ {
					if a[i][j] < a[i][j-1] {
						mp[-1] = true
						break
					}

				}
			}
		}
		if len(mp) == 0 {
			Fprintln(out, 1, 1)
		} else if len(mp) == 2 {
			Fprintln(out, keys[0]+1, keys[1]+1)
		} else {
			Fprintln(out, -1)
		}

	}

}

func MakeGrid(h, w int) [][]int {
	index := make([][]int, h)
	data := make([]int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var T int
	Fscan(in, &T)

	for tt := 0; tt < T; tt++ {
		var n, m int
		Fscan(in, &n, &m)

		a := MakeGrid(n, m)

		use := false
		tj := -1
		fj := -1

		flag := true
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &a[i][j])
				if !use && j > 0 {
					if a[i][j] < a[i][j-1] {
						if tj == -1 {
							tj = j
						} else {
							fj = j
							if a[i][j] <= a[i][tj] {
								tj = tj - 1
							}
						}
					}
				}
			}
			if tj != -1 && fj == -1 {
				tj, fj = tj-1, tj

			}
			if tj != -1 && fj != -1 {
				use = true
			}
		}
		for i := 0; i < n; i++ {
			if tj != -1 && fj != -1 {
				a[i][tj], a[i][fj] = a[i][fj], a[i][tj]
			}
			for j := 1; j < m && flag; j++ {
				if a[i][j] < a[i][j-1] {
					flag = false
				}
			}
		}
		if flag {
			if fj != -1 {
				Fprintln(out, tj+1, fj+1)
			} else {
				Fprintln(out, 1, 1)
			}
		} else {
			Fprintln(out, -1)
		}

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

// An Item is something we manage in a priority queue.
type Item struct {
	value    string // The value of the item; arbitrary.
	priority int    // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].priority > pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

// update modifies the priority and value of an Item in the queue.
func (pq *PriorityQueue) update(item *Item, value string, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
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 tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N,M := gi(),gi(); A := make([][]int,N); for i:=0;i<N;i++ { A[i] = gis(M) }
		done := false; working := make([]int,M); badcols := make([]int,0)
		for i:=0;i<N;i++ {
			row := A[i]; copy(working,row); sort.Slice(working,func(i,j int) bool { return working[i] < working[j] } )
			for i:=0;i<M;i++ { if working[i] != row[i] { badcols = append(badcols,i) } }
			if len(badcols) == 0 { continue }
			if len(badcols) > 2 { fmt.Fprintln(wrtr,-1); done = true; break }
			good := true; c1,c2 := badcols[0],badcols[1]
			for ii:=0;i<N;i++ {
				row := A[ii]; row[c1],row[c2] = row[c2],row[c1]
				for i:=0;i<M-1;i++ { if row[i] > row[i+1] { good = false; break } }
			}
			if !good { fmt.Fprintln(wrtr,-1); } else { fmt.Fprintf(wrtr,"%v %v\n",c1,c2) }
			done = true; break
		}
		if !done { fmt.Fprintln(wrtr,"1 1") }
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
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 tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N,M := gi(),gi(); A := make([][]int,N); for i:=0;i<N;i++ { A[i] = gis(M) }
		potBadCols := make(map[int]bool)
		for i:=0;i<N;i++ {
			row := A[i]
			for j:=0;j<M-1;j++ {
				if row[j] > row[j+1] { potBadCols[j] = true; potBadCols[j+1] = true }
			}
		}
		if len(potBadCols) == 0 { fmt.Fprintf(wrtr,"%v %v\n",1,1); continue }
		if len(potBadCols) > 6 { fmt.Fprintf(wrtr,"-1\n"); continue }
		pb := make([]int,0); for k := range potBadCols { pb = append(pb,k) }
		col1,col2 := -1,-1
		tryit := func(c1,c2 int) bool {
			good := true
			for i:=0;i<N;i++ {
				row := A[i]
				row[c1],row[c2] = row[c2],row[c1]
				for j:=0;j<M-1;j++ {
					if row[j] > row[j+1] { good = false; break }
				}
				row[c1],row[c2] = row[c2],row[c1]
				if !good { break }
			}
			return good
		}
		for i:=0;i<len(pb);i++ {
			for j:=i+1;j<len(pb);j++ {
				tcol1,tcol2 := pb[i],pb[j]
				good := true
				for _,c := range pb { if abs(tcol1-c) > 1 && abs(tcol2-c) > 1 { good = false } }
				if !good { continue }
				if tryit(tcol1,tcol2) { col1,col2 = tcol1,tcol2; break }
			}
			if col1 != -1 { break }
		}
		if col1 != -1 { fmt.Fprintf(wrtr,"%v %v\n",col1+1,col2+1) } else { fmt.Fprintf(wrtr,"-1\n") }
	}
}

package main

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

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

	var T, n, m int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		k := -1
		a := make([][]int, n)
		for i := range a {
			a[i] = make([]int, m)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
			if !sort.IntsAreSorted(a[i]) {
				k = i
			}
		}
		if k < 0 {
			Fprintln(out, 1, 1)
			continue
		}
		ps := []int{}
		for j := 1; j < m; j++ {
			if a[k][j-1] > a[k][j] {
				if len(ps) == 2 {
					Fprintln(out, -1)
					continue o
				}
				ps = append(ps, j)
			}
		}
		var i, j int
		if len(ps) == 1 {
			j = ps[0]
			i = sort.SearchInts(a[k][:j], a[k][j]+1)
		} else {
			i, j = ps[0]-1, ps[1]
		}
		for _, r := range a {
			r[i], r[j] = r[j], r[i]
			if !sort.IntsAreSorted(r) {
				Fprintln(out, -1)
				continue o
			}
		}
		Fprintln(out, i+1, j+1)
	}
}

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

package main

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

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, m int
		Fscan(in, &n, &m)
		grid := make([][]int, n)
		for i := 0; i < n; i++ {
			grid[i] = make([]int, m)
		}
		var fi = -1
		var se = -1
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				Fscan(in, &grid[i][j])
			}
		}
		var get bool
		var cnt int
		var row = []int{}
		for i := 0; i < n; i++ {
			col := make([]int, m)
			for k := 0; k < m; k++ {
				col[k] = grid[i][k]
			}
			sort.Ints(col)
			pos := []int{}
			for j := 0; j < m; j++ {
				if grid[i][j] != col[j] {
					pos = append(pos, j+1)
				}
			}
			if len(pos) > 2 {
				Fprintln(out, -1)
				return
			}
			//Fprintln(out, "---", pos)
			if len(pos) == 2 {
				cnt++
				if !get {
					fi = pos[0]
					se = pos[1]
					get = true
				} else {
					if fi != pos[0] || se != pos[1] {
						Fprintln(out, -1)
					}
				}
			}
			if len(pos) == 0 {
				row = append(row, i)
			}
		}
		if !get {
			Fprintln(out, 1, 1)
		} else {
			for i := 0; i < len(row); i++ {
				if grid[row[i]][fi-1] == grid[row[i]][se-1] {
					cnt++
				}
			}
			if cnt < n {
				Fprintln(out, -1)
				return
			}
			Fprintln(out, fi, se)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }


Hands that shed innocent blood!There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li.You are given lengths of the claws. You need to find the total number of alive people after the bell rings.

The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people. Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.

Print one integer — the total number of alive people after the bell rings.

NoteIn first sample the last person kills everyone in front of him.

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	n := readInt()

	var alives []int
	for i := 0; i < n; i++ {
		hook := readInt()
		dead := 0
		for j := len(alives) - 1; j >= 0; j-- {
			if i-alives[j] > hook {
				break
			}
			dead++
		}
		alives = append(alives[:len(alives)-dead], i)
	}

	fmt.Println(len(alives))
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

package main

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

func solve() {
	n := readInt()

	// read in all the claw lengths
	claws := make([]int, n, n)
	for i, _ := range claws {
		claws[i] = readInt()
	}

	alive_marker := n - 1
	var nalive = 0
	for i := n - 1; i >= 0; i-- {
		if i == alive_marker {
			nalive++
		}

		// move the marker to the left
		next := i - claws[i] - 1
		if next < alive_marker {
			alive_marker = next
		}

		if alive_marker < 0 {
			// noone else alive
			break
		}
	}
	fmt.Println(nalive)
}

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

package main

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

func solve() {
	n := readInt()
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = readInt64()
	}
	v := make([]bool, n)
	cnt := 0
	for i := n - 1; i >= 0; i-- {
		if !v[i] {
			l := a[i]
			for j := i - 1; j >= 0 && !v[j] && l > 0; j-- {
				cnt++
				v[j] = true
				l--
				l = max(a[j], l)
			}
		}
	}
	fmt.Println(n - cnt)
}

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

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

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

package main

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

type wrath struct{}

func (c *wrath) solve() int {
	inp := bufio.NewReader(os.Stdin)

	// read n
	var n int
	fmt.Fscanf(inp, "%d\n", &n)
	if n <= 1 {
		return 1
	}

	// stack
	stack := make([]int, 0, n>>1)

	var claw, killTo, i, j int
	for i = 0; i < n; i++ {
		fmt.Fscanf(inp, "%d", &claw)

		// i - claw
		if killTo = i - claw; killTo < 0 {
			killTo = 0
		}

		for j = len(stack) - 1; j >= 0; j-- {
			if stack[j] < killTo {
				break
			}
		}

		if j != len(stack)-1 {
			stack = stack[:j+1]
		}
		stack = append(stack, i)
	}

	return len(stack)
}

func main() {
	var w wrath
	fmt.Print(w.solve())
}

package main

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

var local = false
var scanner *bufio.Scanner

func main() {
	setup()
	n := readInt()

	if n == 1 {
		fmt.Println("1")
		return
	}

	l := make([]int, n)
	f := make([]bool, n)
	x := make([]int, n)
	for i := 0; i < n; i++ {
		l[i] = readInt()
		f[i] = true
	}

	for i := n - 2; i >= 0; i-- {
		xif := math.Max(float64(l[i + 1]), float64(x[i + 1]))
		xi := int(xif)
		if xi > 0 {
			x[i] = xi - 1
			f[i] = false
		}
	}

	nAlive := 0
	for i := 0; i < n; i++ {
		if f[i] {
			nAlive++;
		}
	}

	fmt.Println(nAlive)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

func readBigInt() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}

package main

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

var local = false
var scanner *bufio.Scanner

var l [1000000]int
var f [1000000]bool
var x [1000000]int

func main() {
	setup()
	n := readInt()

	if n == 1 {
		fmt.Println("1")
		return
	}

	for i := 0; i < n; i++ {
		l[i] = readInt()
		f[i] = true
	}

	for i := n - 2; i >= 0; i-- {
		xif := math.Max(float64(l[i + 1]), float64(x[i + 1]))
		xi := int(xif)
		if xi > 0 {
			x[i] = xi - 1
			f[i] = false
		}
	}

	nAlive := 0
	for i := 0; i < n; i++ {
		if f[i] {
			nAlive++;
		}
	}

	fmt.Println(nAlive)
}

func setup() {
	source := os.Stdin
	if local == true {
		file, _ := os.Open("input.txt")
		source = file
	}
	scanner = bufio.NewScanner(source)
	scanner.Split(bufio.ScanWords)
}

func readInt() int {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 0)
	return int(ans)
}

func readBigInt() int64 {
	scanner.Scan()
	ans, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return ans
}


You are given an array $$$a$$$ of length $$$n$$$. You are asked to process $$$q$$$ queries of the following format: given integers $$$i$$$ and $$$x$$$, multiply $$$a_i$$$ by $$$x$$$.After processing each query you need to output the greatest common divisor (GCD) of all elements of the array $$$a$$$.Since the answer can be too large, you are asked to output it modulo $$$10^9+7$$$.

The first line contains two integers — $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$) — the elements of the array $$$a$$$ before the changes. The next $$$q$$$ lines contain queries in the following format: each line contains two integers $$$i$$$ and $$$x$$$ ($$$1 \le i \le n$$$, $$$1 \le x \le 2 \cdot 10^5$$$).

Print $$$q$$$ lines: after processing each query output the GCD of all elements modulo $$$10^9+7$$$ on a separate line.

NoteAfter the first query the array is $$$[12, 6, 8, 12]$$$, $$$\operatorname{gcd}(12, 6, 8, 12) = 2$$$.After the second query — $$$[12, 18, 8, 12]$$$, $$$\operatorname{gcd}(12, 18, 8, 12) = 2$$$.After the third query — $$$[12, 18, 24, 12]$$$, $$$\operatorname{gcd}(12, 18, 24, 12) = 6$$$.Here the $$$\operatorname{gcd}$$$ function denotes the greatest common divisor.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1493D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}

	const mx int = 2e5
	lpf := [mx + 1]int{}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	n, q := r(), r()
	cnts := make([]map[int]int, n)
	for i := range cnts {
		cnts[i] = map[int]int{}
	}
	cc := [mx + 1][]int{}
	g := int64(1)
	add := func(i, v int) {
		cnt := cnts[i]
		for v > 1 {
			for p := lpf[v]; lpf[v] == p; v /= p {
				c := cnt[p]
				cnt[p]++
				if len(cc[p]) <= c {
					cc[p] = append(cc[p], 0)
				}
				if cc[p][c]++; cc[p][c] == n {
					g = g * int64(p) % (1e9 + 7)
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		add(i, r())
	}
	for ; q > 0; q-- {
		add(r()-1, r())
		Fprintln(out, g)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1493D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}

	const mx int = 2e5
	primes := make([]int, 0, 17984)
	lpf := [mx + 1]int{}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			primes = append(primes, i)
			lpf[i] = i
		}
		for _, p := range primes {
			if p*i > mx {
				break
			}
			lpf[p*i] = p
		}
	}

	n, q := r(), r()
	dCnt := [mx + 1][]int{}
	posCnt := make([]map[int]int, n)
	for i := range posCnt {
		posCnt[i] = map[int]int{}
	}
	g := int64(1)
	add := func(i, v int) {
		pc := posCnt[i]
		for v > 1 {
			for p := lpf[v]; lpf[v] == p; v /= p {
				c := pc[p]
				pc[p]++
				if len(dCnt[p]) <= c {
					dCnt[p] = append(dCnt[p], 0)
				}
				if dCnt[p][c]++; dCnt[p][c] == n {
					g = g * int64(p) % (1e9 + 7)
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		add(i, r())
	}
	for ; q > 0; q-- {
		add(r()-1, r())
		Fprintln(out, g)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1493D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}

	const mx int = 2e5
	primes := make([]int, 0, 17984)
	lpf := [mx + 1]int{}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			primes = append(primes, i)
			lpf[i] = i
		}
		for _, p := range primes {
			if p*i > mx {
				break
			}
			lpf[p*i] = p
			if i%p == 0 {
				break
			}
		}
	}

	n, q := r(), r()
	dCnt := [mx + 1][]int{}
	posCnt := make([]map[int]int, n)
	for i := range posCnt {
		posCnt[i] = map[int]int{}
	}
	g := int64(1)
	add := func(i, v int) {
		pc := posCnt[i]
		for v > 1 {
			for p := lpf[v]; lpf[v] == p; v /= p {
				c := pc[p]
				pc[p]++
				if len(dCnt[p]) <= c {
					dCnt[p] = append(dCnt[p], 0)
				}
				if dCnt[p][c]++; dCnt[p][c] == n {
					g = g * int64(p) % (1e9 + 7)
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		add(i, r())
	}
	for ; q > 0; q-- {
		add(r()-1, r())
		Fprintln(out, g)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1493D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}

	const mx int = 2e5
	lpf := [mx + 1]int{}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	n, q := r(), r()
	dCnt := [mx + 1][]int{}
	posCnt := make([]map[int]int, n)
	for i := range posCnt {
		posCnt[i] = map[int]int{}
	}
	g := int64(1)
	add := func(i, v int) {
		pc := posCnt[i]
		for v > 1 {
			for p := lpf[v]; lpf[v] == p; v /= p {
				c := pc[p]
				pc[p]++
				if len(dCnt[p]) <= c {
					dCnt[p] = append(dCnt[p], 0)
				}
				if dCnt[p][c]++; dCnt[p][c] == n {
					g = g * int64(p) % (1e9 + 7)
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		add(i, r())
	}
	for ; q > 0; q-- {
		add(r()-1, r())
		Fprintln(out, g)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type vi struct{ v, i int }
type hp []*vi

func (h hp) Len() int            { return len(h) }
func (h hp) Less(i, j int) bool  { return h[i].v < h[j].v }
func (h hp) Swap(i, j int)       { h[i], h[j] = h[j], h[i]; h[i].i = i; h[j].i = j }
func (h *hp) Push(v interface{}) { *h = append(*h, v.(*vi)) }
func (h *hp) Pop() interface{}   { return nil }
func (h *hp) push(v int) *vi     { p := &vi{v, len(*h)}; heap.Push(h, p); return p }

func CF1493D(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}

	const mx int = 2e5
	lpf := [mx + 1]int{}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	const mod int64 = 1e9 + 7
	pow := func(x int64, n int) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 > 0 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}

	n, q := r(), r()
	hs := [mx + 1]hp{}
	ps := make([]map[int]*vi, n)
	for i := range ps {
		ps[i] = map[int]*vi{}
		v := r()
		for v > 1 {
			p := lpf[v]
			e := 1
			for v /= p; lpf[v] == p; v /= p {
				e++
			}
			ps[i][p] = hs[p].push(e)
		}
	}
	g := int64(1)
	for p, h := range hs[:] {
		if len(h) == n {
			g = g * pow(int64(p), h[0].v) % mod
		}
	}
	for ; q > 0; q-- {
		i, v := r()-1, r()
		for v > 1 {
			p := lpf[v]
			e := 1
			for v /= p; lpf[v] == p; v /= p {
				e++
			}
			h := hs[p]
			before := 0
			if len(h) == n {
				before = h[0].v
			}
			if vi := ps[i][p]; vi == nil {
				ps[i][p] = h.push(e)
				hs[p] = h
			} else {
				vi.v += e
				heap.Fix(&h, vi.i)
			}
			if len(h) == n {
				g = g * pow(int64(p), h[0].v-before) % mod
			}
		}
		Fprintln(out, g)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type vi struct{ v, i int }
type hp []*vi

func (h hp) Len() int            { return len(h) }
func (h hp) Less(i, j int) bool  { return h[i].v < h[j].v }
func (h hp) Swap(i, j int)       { h[i], h[j] = h[j], h[i]; h[i].i = i; h[j].i = j }
func (h *hp) Push(v interface{}) { *h = append(*h, v.(*vi)) }
func (h *hp) Pop() interface{}   { return nil }
func (h *hp) push(v int) *vi     { p := &vi{v, len(*h)}; heap.Push(h, p); return p }

func CF1493D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mx int = 2e5
	lpf := [mx + 1]int{}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	const mod int64 = 1e9 + 7
	pow := func(x int64, n int) int64 {
		res := int64(1)
		for ; n > 0; n >>= 1 {
			if n&1 > 0 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}

	var n, q, i, v int
	Fscan(in, &n, &q)
	hs := [mx + 1]hp{}
	ps := make([]map[int]*vi, n)
	for i := range ps {
		ps[i] = map[int]*vi{}
		Fscan(in, &v)
		for v > 1 {
			p := lpf[v]
			e := 1
			for v /= p; lpf[v] == p; v /= p {
				e++
			}
			ps[i][p] = hs[p].push(e)
		}
	}
	g := int64(1)
	for p, h := range hs[:] {
		if len(h) == n {
			g = g * pow(int64(p), h[0].v) % mod
		}
	}
	for ; q > 0; q-- {
		Fscan(in, &i, &v)
		for v > 1 {
			p := lpf[v]
			e := 1
			for v /= p; lpf[v] == p; v /= p {
				e++
			}
			h := hs[p]
			before := 0
			if len(h) == n {
				before = h[0].v
			}
			if vi := ps[i-1][p]; vi == nil {
				ps[i-1][p] = h.push(e)
				hs[p] = h
			} else {
				vi.v += e
				heap.Fix(&h, vi.i)
			}
			if len(h) == n {
				g = g * pow(int64(p), h[0].v-before) % mod
			}
		}
		Fprintln(out, g)
	}
}

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

package main

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

const mod int64 = 1e9 + 7

func binpow(a, n int64) int64 {
	var res int64 = 1
	for n > 0 {
		if n&1 == 1 {
			res *= a
			res %= mod
		}
		n >>= 1
		a *= a
		a %= mod
	}
	return res % mod
}

func sieve(n int) []int64 {
	mindiv := make([]int64, n+1)
	for x := 1; x <= n; x++ {
		mindiv[x] = int64(x)
	}

	for x := 2; x*x <= n; x++ {
		if mindiv[x] == int64(x) {
			for y := x * x; y <= n; y += x {
				mindiv[y] = int64(x)
			}
		}
	}

	return mindiv
}

var mindiv []int64 = sieve(2e5 + 1)

func factor(n int64) map[int64]int64 {
	degs := make(map[int64]int64)
	for n > 1 {
		md := mindiv[n]
		var deg int64
		for n%md == 0 {
			deg++
			n /= md
		}
		degs[md] = deg
	}
	return degs
}

func solveD(b []int64, qq [][2]int64) {
	a := make([]map[int64]int64, len(b))
	for i := range b {
		a[i] = make(map[int64]int64)
		for k, v := range factor(b[i]) {
			a[i][k] = v
		}
	}

	for _, q := range qq {
		i, x := q[0], q[1]
		for k, v := range factor(x) {
			a[i][k] += v
		}
	}

	minDeg := make(map[int64]int64)
	for k, v := range a[0] {
		minDeg[k] = v
	}
	for i := 1; i < len(a); i++ {
		for p, now := range a[i] {
			if now < minDeg[p] {
				minDeg[p] = now
			}
		}
		for p := range minDeg {
			if a[i][p] < minDeg[p] {
				minDeg[p] = a[i][p]
			}
		}
	}

	var res int64 = 1
	for k, v := range minDeg {
		res *= binpow(k, v)
		res %= mod
	}

	ans := make([]int64, 0)
	ans = append(ans, res)

	for i := len(qq) - 1; i >= 1; i-- {
		j, x := qq[i][0], qq[i][1]

		for p, d := range factor(x) {
			prevMin := minDeg[p]
			a[j][p] -= d
			if prevMin > a[j][p] {
				minDeg[p] = a[j][p]

				if minDeg[p] < 0 {
					panic("123")
				}

				diff := prevMin - minDeg[p]
				res *= binpow(p, diff*(mod-2))
				res %= mod
			}
		}

		ans = append(ans, res%mod)
	}

	for i := len(ans) - 1; i >= 0; i-- {
		printf("%d\n", ans[i])
	}
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	// scan(&T)
	for t := 0; t < T; t++ {
		var n, q int
		scan(&n, &q)
		b := make([]int64, n)
		for i := range b {
			scan(&b[i])
		}
		qq := make([][2]int64, q)
		for i := range qq {
			scan(&qq[i][0], &qq[i][1])
			qq[i][0]--
		}
		solveD(b, qq)
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

package main

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

const mod int64 = 1e9 + 7

func binpow(a, n int64) int64 {
	var res int64 = 1
	for n > 0 {
		if n&1 == 1 {
			res *= a
			res %= mod
		}
		n >>= 1
		a *= a
		a %= mod
	}
	return res % mod
}

func sieve(n int) []int64 {
	mindiv := make([]int64, n+1)
	for x := 1; x <= n; x++ {
		mindiv[x] = int64(x)
	}

	for x := 2; x*x <= n; x++ {
		if mindiv[x] == int64(x) {
			for y := x * x; y <= n; y += x {
				mindiv[y] = int64(x)
			}
		}
	}

	return mindiv
}

var mindiv []int64 = sieve(2e5 + 1)

func factor(n int64) map[int64]int64 {
	degs := make(map[int64]int64)
	for n > 1 {
		md := mindiv[n]
		var deg int64
		for n%md == 0 {
			deg++
			n /= md
		}
		degs[md] = deg
	}
	return degs
}

func solveD(b []int64, qq [][2]int64) {
	a := make([]map[int64]int64, len(b))
	for i := range b {
		a[i] = make(map[int64]int64)
		for k, v := range factor(b[i]) {
			a[i][k] = v
		}
	}

	for _, q := range qq {
		i, x := q[0], q[1]
		for k, v := range factor(x) {
			a[i][k] += v
		}
	}

	minDeg := make(map[int64]int64)
	for k, v := range a[0] {
		minDeg[k] = v
	}
	for i := 1; i < len(a); i++ {
		for p, now := range a[i] {
			if prev, ok := minDeg[p]; ok && now < prev {
				minDeg[p] = now
			}
		}
	}

	var res int64 = 1
	for k, v := range minDeg {
		res *= binpow(k, v)
		res %= mod
	}

	ans := make([]int64, 0)
	ans = append(ans, res)

	for i := len(qq) - 1; i >= 1; i-- {
		j, x := qq[i][0], qq[i][1]

		for p, d := range factor(x) {
			prevMin := minDeg[p]
			a[j][p] -= d
			if prevMin > a[j][p] {
				minDeg[p] = a[j][p]

				if minDeg[p] < 0 {
					panic("123")
				}

				diff := prevMin - minDeg[p]
				res *= binpow(p, diff*(mod-2))
				res %= mod
			}
		}

		ans = append(ans, res%mod)
	}

	for i := len(ans) - 1; i >= 0; i-- {
		printf("%d\n", ans[i])
	}
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	// scan(&T)
	for t := 0; t < T; t++ {
		var n, q int
		scan(&n, &q)
		b := make([]int64, n)
		for i := range b {
			scan(&b[i])
		}
		qq := make([][2]int64, q)
		for i := range qq {
			scan(&qq[i][0], &qq[i][1])
			qq[i][0]--
		}
		solveD(b, qq)
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

const inf = 1 << 60

func gcd(a, b int64) int64 {
	for a > 0 && b > 0 {
		a, b = b, a%b
	}
	return a + b
}

type segtree []segtreenode

type segtreenode struct {
	node, l, r int

	g int64
}

func newSegtree(v []int64) segtree {
	tr := make(segtree, 4*len(v))
	tr.build(0, v, 0, len(v)-1)
	return tr
}

func (tree segtree) build(node int, v []int64, l, r int) {
	tree[node] = segtreenode{
		node: node, l: l, r: r,
	}
	if l == r {
		tree[node].g = v[l]
		return
	}
	m := l + (r-l)/2
	tree.build(2*node+1, v, l, m)
	tree.build(2*node+2, v, m+1, r)
	tree[node].g = gcd(tree[2*node+1].g, tree[2*node+2].g)
}

func (tree segtree) get(node, l, r int) int64 {
	if l > r {
		return inf
	}

	nl, nr := tree[node].l, tree[node].r

	if r < nl || nr < l {
		return inf
	}

	if l <= nl && nr <= r {
		return tree[node].g
	}

	return gcd(
		tree.get(2*node+1, l, r),
		tree.get(2*node+2, l, r),
	)
}

func (tree segtree) update(node, idx int, val int64) int64 {
	nl, nr := tree[node].l, tree[node].r

	if idx <= nl && nr <= idx {
		tree[node].g = val
	}
	return -1
}

package main

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

const mod int64 = 1e9 + 7

func binpow(a, n, mod int64) int64 {
	var res int64 = 1
	for n > 0 {
		if n&1 == 1 {
			res *= a
			res %= mod
		}
		n >>= 1
		a *= a
		a %= mod
	}
	return res % mod
}

func sieve(n int) []int64 {
	mindiv := make([]int64, n+1)
	for x := 1; x <= n; x++ {
		mindiv[x] = int64(x)
	}

	for x := 2; x*x <= n; x++ {
		if mindiv[x] == int64(x) {
			for y := x * x; y <= n; y += x {
				mindiv[y] = int64(x)
			}
		}
	}

	return mindiv
}

var mindiv []int64 = sieve(2e5 + 1)

func factor(n int64) map[int64]int64 {
	degs := make(map[int64]int64)
	for n > 1 {
		md := mindiv[n]
		var deg int64
		for n%md == 0 {
			deg++
			n /= md
		}
		degs[md] = deg
	}
	return degs
}

func solveD(b []int64, qq [][2]int64) {
	a := make([]map[int64]int64, len(b))
	for i := range b {
		a[i] = make(map[int64]int64)
		for k, v := range factor(b[i]) {
			a[i][k] = v
		}
	}

	for _, q := range qq {
		i, x := q[0], q[1]
		for k, v := range factor(x) {
			a[i][k] += v
		}
	}

	minDeg := make(map[int64]int64)
	for k, v := range a[0] {
		minDeg[k] = v
	}
	for i := 1; i < len(a); i++ {
		for k, v := range a[i] {
			if w, ok := minDeg[k]; ok && v < w {
				minDeg[k] = v
			}
		}
	}

	var res int64 = 1
	for k, v := range minDeg {
		res *= binpow(k, v, mod)
		res %= mod
	}

	ans := make([]int64, 0, len(qq))
	ans = append(ans, res)
	for i := len(qq) - 1; i >= 1; i-- {
		i, x := qq[i][0], qq[i][1]

		for p, d := range factor(x) {
			prev := minDeg[p]
			if prev > a[i][p]-d {
				a[i][p] -= d
				minDeg[p] = a[i][p]

				y := binpow(p, prev-minDeg[p], mod)
				y = binpow(y, mod-2, mod)

				res *= y
				res %= mod
			}
		}

		ans = append(ans, res)
	}

	for i := len(ans) - 1; i >= 0; i-- {
		printf("%d\n", ans[i])
	}
}

func main() {
	defer writer.Flush()
	//redirectInputToFile(reader, "input.txt")

	T := 1
	// scan(&T)
	for t := 0; t < T; t++ {
		var n, q int
		scan(&n, &q)
		b := make([]int64, n)
		for i := range b {
			scan(&b[i])
		}
		qq := make([][2]int64, q)
		for i := range qq {
			scan(&qq[i][0], &qq[i][1])
			qq[i][0]--
		}
		solveD(b, qq)
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

const inf = 1 << 60

func gcd(a, b int64) int64 {
	for a > 0 && b > 0 {
		a, b = b, a%b
	}
	return a + b
}

type segtree []segtreenode

type segtreenode struct {
	node, l, r int

	g int64
}

func newSegtree(v []int64) segtree {
	tr := make(segtree, 4*len(v))
	tr.build(0, v, 0, len(v)-1)
	return tr
}

func (tree segtree) build(node int, v []int64, l, r int) {
	tree[node] = segtreenode{
		node: node, l: l, r: r,
	}
	if l == r {
		tree[node].g = v[l]
		return
	}
	m := l + (r-l)/2
	tree.build(2*node+1, v, l, m)
	tree.build(2*node+2, v, m+1, r)
	tree[node].g = gcd(tree[2*node+1].g, tree[2*node+2].g)
}

func (tree segtree) get(node, l, r int) int64 {
	if l > r {
		return inf
	}

	nl, nr := tree[node].l, tree[node].r

	if r < nl || nr < l {
		return inf
	}

	if l <= nl && nr <= r {
		return tree[node].g
	}

	return gcd(
		tree.get(2*node+1, l, r),
		tree.get(2*node+2, l, r),
	)
}

func (tree segtree) update(node, idx int, val int64) int64 {
	nl, nr := tree[node].l, tree[node].r

	if idx <= nl && nr <= idx {
		tree[node].g = val
	}
	return -1
}


You've got an array a, consisting of n integers a1, a2, ..., an. You are allowed to perform two operations on this array:  Calculate the sum of current array elements on the segment [l, r], that is, count value al + al + 1 + ... + ar.  Apply the xor operation with a given number x to each array element on the segment [l, r], that is, execute . This operation changes exactly r - l + 1 array elements. Expression  means applying bitwise xor operation to numbers x and y. The given operation exists in all modern programming languages, for example in language C++ and Java it is marked as "^", in Pascal — as "xor".You've got a list of m operations of the indicated type. Your task is to perform all given operations, for each sum query you should print the result you get.

The first line contains integer n (1 ≤ n ≤ 105) — the size of the array. The second line contains space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 106) — the original array. The third line contains integer m (1 ≤ m ≤ 5·104) — the number of operations with the array. The i-th of the following m lines first contains an integer ti (1 ≤ ti ≤ 2) — the type of the i-th query. If ti = 1, then this is the query of the sum, if ti = 2, then this is the query to change array elements. If the i-th operation is of type 1, then next follow two integers li, ri (1 ≤ li ≤ ri ≤ n). If the i-th operation is of type 2, then next follow three integers li, ri, xi (1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 106). The numbers on the lines are separated by single spaces.

For each query of type 1 print in a single line the sum of numbers on the given segment. Print the answers to the queries in the order in which the queries go in the input. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d specifier.

package main

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

type scanner struct {
	*bufio.Scanner
}

func (s *scanner) nextInt() int {
	s.Scan()
	v, _ := strconv.Atoi(s.Text())
	return v
}

func (s *scanner) nextInt64() int64 {
	s.Scan()
	v, _ := strconv.ParseInt(s.Text(), 10, 64)
	return v
}

var (
	label []int
	freq  [][]int
	a     []int

	n int
	m int
)

const maxbit = 24

func atof(a int) []int {
	var f []int
	for i := 0; i < maxbit; i++ {
		if (a & (1 << uint(i))) != 0 {
			f = append(f, i)
		}
	}
	return f
}

// evaluate
func eval(idx int) int64 {
	var res int64
	for i, f := range freq[idx] {
		res += (1 << uint(i)) * int64(f)
	}
	return res
}

func build(sl, sr, idx int) {
	if sl == sr {
		for _, i := range atof(a[sl]) {
			freq[idx][i] = 1
		}
		return
	}

	m, lidx, ridx := (sl+sr)>>1, idx<<1, idx<<1|1
	build(sl, m, lidx)
	build(m+1, sr, ridx)

	for i := 0; i < maxbit; i++ {
		freq[idx][i] = freq[lidx][i] + freq[ridx][i]
	}
}

func query(sl, sr, l, r, idx int) int64 {
	// fmt.Println(sl, sr, l, r, idx)
	// segment range is within query range ? report
	if l <= sl && sr <= r {
		return eval(idx)
	}
	// disjoint ? quit
	if r < sl || sr < l {
		return 0
	}
	// push label down
	m, lidx, ridx := (sr+sl)>>1, idx<<1, idx<<1|1
	updateInternal(sl, m, lidx, label[idx])
	updateInternal(m+1, sr, ridx, label[idx])
	label[idx] = 0

	return query(sl, m, l, r, lidx) + query(m+1, sr, l, r, ridx)
}

func updateInternal(sl, sr, idx, v int) {
	label[idx] ^= v
	for _, i := range atof(v) {
		freq[idx][i] = (sr - sl + 1) - freq[idx][i]
	}
}

func update(sl, sr, l, r, idx, v int) {
	// segment range is within query range ? report
	if l <= sl && sr <= r {
		updateInternal(sl, sr, idx, v)
		return
	}
	// disjoint ? quit
	if r < sl || sr < l {
		return
	}
	// push label down
	m, lidx, ridx := (sr+sl)>>1, idx<<1, idx<<1|1
	updateInternal(sl, m, lidx, label[idx])
	updateInternal(m+1, sr, ridx, label[idx])
	label[idx] = 0

	update(sl, m, l, r, lidx, v)
	update(m+1, sr, l, r, ridx, v)

	for i := 0; i < maxbit; i++ {
		freq[idx][i] = freq[lidx][i] + freq[ridx][i]
	}
}

func main() {
	in := &scanner{bufio.NewScanner(os.Stdin)}
	in.Split(bufio.ScanWords)

	n = in.nextInt()
	var offset int
	for offset = 1; offset <= n; offset <<= 1 {
	}
	label = make([]int, 2*offset)
	freq = make([][]int, 2*offset)
	a = make([]int, n+1)
	for i := 1; i < 2*offset; i++ {
		freq[i] = make([]int, maxbit)
	}
	for i := 1; i <= n; i++ {
		a[i] = in.nextInt()
	}

	build(1, n, 1)

	m = in.nextInt()
	for m > 0 {
		switch t := in.nextInt(); t {
		case 1:
			l, r := in.nextInt(), in.nextInt()
			fmt.Println(query(1, n, l, r, 1))
		case 2:
			l, r, v := in.nextInt(), in.nextInt(), in.nextInt()
			update(1, n, l, r, 1, v)
		}
		m--
	}
}

package main

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

type scanner struct {
	*bufio.Scanner
}

func (s *scanner) nextInt() int {
	s.Scan()
	v, _ := strconv.Atoi(s.Text())
	return v
}

func (s *scanner) nextInt64() int64 {
	s.Scan()
	v, _ := strconv.ParseInt(s.Text(), 10, 64)
	return v
}

type SegmentTree []*Segment

type Segment struct {
	l, r  int
	label int
	freq  []int

	ls, rs *Segment
}

const maxbit = 25

func newSegment(l, r int) *Segment {
	return &Segment{
		l:     l,
		r:     r,
		label: 0,
		freq:  make([]int, maxbit),
		ls:    nil,
		rs:    nil,
	}
}

func (s Segment) next() []*Segment {
	var res []*Segment
	if s.ls != nil {
		res = append(res, s.ls)
	}
	if s.rs != nil {
		res = append(res, s.rs)
	}
	return res
}

func (s Segment) within(l, r int) bool {
	return (l <= s.l && s.r <= r)
}

func (s Segment) disjoint(l, r int) bool {
	return (r < s.l) || (s.r < l)
}

func (s *Segment) update(label int) {
	s.label ^= label
	n := s.r - s.l + 1
	for i, p2 := 0, 1; i < maxbit; i, p2 = i+1, p2*2 {
		if (label & p2) != 0 {
			s.freq[i] = n - s.freq[i]
		}
	}
}

func (s *Segment) populate() {
	if s.ls != nil {
		s.ls.update(s.label)
	}
	if s.rs != nil {
		s.rs.update(s.label)
	}
	s.label=0
}

func (s *Segment) refresh() {
	if s.ls == nil {
		return
	}
	for i := 0; i < maxbit; i++ {
		s.freq[i] = s.ls.freq[i] + s.rs.freq[i]
	}
}

func (s *Segment) summary() int64 {
	var res int64
	for i, p2 := 0, int64(1); i < maxbit; i, p2 = i+1, p2*2 {
		res += p2 * int64(s.freq[i])
	}
	return res
}

func Init(n int, a []int) SegmentTree {
	st := SegmentTree{}
	st = append(st, newSegment(1, n))
	for i := 0; i < len(st); i++ {
		s := st[i]
		l, r := s.l, s.r
		if l == r {
			continue
		}
		m := (l + r) / 2
		s.ls = newSegment(l, m)
		s.rs = newSegment(m+1, r)
		st = append(st, s.ls, s.rs)
	}
	return st
}

func (st SegmentTree) Query(l, r int) int64 {
	q := []*Segment{st[0]}
	var res int64

	for len(q) > 0 {
		s := q[0]
		q = q[1:]

		if s.within(l, r) {
			res += s.summary()
			continue
		}
		if s.disjoint(l, r) {
			continue
		}

		s.populate()
		q = append(q, s.next()...)
	}
	return res
}

func (st SegmentTree) Update(l, r int, label int) {
	// fmt.Printf("Updating %d %d %d\n", l, r, label)
	q := []*Segment{st[0]}
	p := []*Segment{}

	for len(q) > 0 {
		s := q[0]
		q = q[1:]

		if s.within(l, r) {
			s.update(label)
			continue
		}
		if s.disjoint(l, r) {
			continue
		}
		s.populate()
		p = append(p, s)
		q = append(q, s.next()...)
	}
	for _, s := range p {
		defer s.refresh()
	}
}

func main() {
	in := &scanner{bufio.NewScanner(os.Stdin)}
	in.Split(bufio.ScanWords)
	n := in.nextInt()
	a := make([]int, n+2)
	for i := 1; i <= n; i++ {
		a[i] = in.nextInt()
	}
	tree := Init(n, a)
	for i, v := range a {
		tree.Update(i, i, v)
	}
	// for _, s := range tree {
	// 	fmt.Println(*s)
	// }

	for m := in.nextInt(); m > 0; m-- {
		switch t := in.nextInt(); t {
		case 1:
			l, r := in.nextInt(), in.nextInt()
			// fmt.Println("Got", t, l, r)
			// fmt.Println("Answer", tree.Query(l, r))
			fmt.Println(tree.Query(l, r))
		case 2:
			l, r, x := in.nextInt(), in.nextInt(), in.nextInt()
			// fmt.Println("Got", t, l, r, x)
			// fmt.Println("Update")
			tree.Update(l, r, x)
		}
	}

}

package main

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

type node struct {
	l, r        int
	sum         int
	revChildren bool
}
type segTree []node

func (t segTree) _pushUp(o int) {
	lo, ro := t[o<<1], t[o<<1|1]
	t[o].sum = lo.sum + ro.sum
}

func (t segTree) _build(arr []int, pos uint8, o, l, r int) {
	t[o].l, t[o].r = l, r
	if l == r {
		t[o].sum = arr[l-1] >> pos & 1
		return
	}
	mid := (l + r) >> 1
	t._build(arr, pos, o<<1, l, mid)
	t._build(arr, pos, o<<1|1, mid+1, r)
	t._pushUp(o)
}

func (t segTree) _spread(o int) {
	if t[o].revChildren {
		lo, ro := &t[o<<1], &t[o<<1|1]
		lo.sum = lo.r - lo.l + 1 - lo.sum
		ro.sum = ro.r - ro.l + 1 - ro.sum
		lo.revChildren = !lo.revChildren
		ro.revChildren = !ro.revChildren
		t[o].revChildren = false
	}
}

func (t segTree) _rev(o, l, r int) {
	ol, or := t[o].l, t[o].r
	if l <= ol && or <= r {
		t[o].sum = or - ol + 1 - t[o].sum
		t[o].revChildren = !t[o].revChildren
		return
	}
	t._spread(o)
	mid := (ol + or) >> 1
	if l <= mid {
		t._rev(o<<1, l, r)
	}
	if mid < r {
		t._rev(o<<1|1, l, r)
	}
	t._pushUp(o)
}

func (t segTree) _query(o, l, r int) (res int) {
	if l <= t[o].l && t[o].r <= r {
		return t[o].sum
	}
	t._spread(o)
	mid := (t[o].l + t[o].r) >> 1
	if l <= mid {
		res += t._query(o<<1, l, r)
	}
	if mid < r {
		res += t._query(o<<1|1, l, r)
	}
	return
}

func (t segTree) init(arr []int, pos uint8) { t._build(arr, pos, 1, 1, len(arr)) }
func (t segTree) rev(l, r int)              { t._rev(1, l, r) }
func (t segTree) query(l, r int) int        { return t._query(1, l, r) }

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

	var n, q int
	Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		Fscan(in, &arr[i])
	}
	trees := make([]segTree, 20)
	for i := range trees {
		trees[i] = make(segTree, 4*n)
		trees[i].init(arr, uint8(i))
	}

	for Fscan(in, &q); q > 0; q-- {
		var op, l, r, x int
		Fscan(in, &op, &l, &r)
		if op == 1 {
			sum := int64(0)
			for i, t := range trees {
				sum += 1 << uint(i) * int64(t.query(l, r))
			}
			Fprintln(out, sum)
		} else {
			Fscan(in, &x)
			for i, t := range trees {
				if x>>uint(i)&1 == 1 {
					t.rev(l, r)
				}
			}
		}
	}
}

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

package main

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

var w *bufio.Writer

var sc *bufio.Scanner

const minus, zero byte = '-', '0'

func nextInt() int {
  var ans, fst int = 0, 0
  var neg bool = false
  sc.Scan()
  if sc.Bytes()[0] == minus {
    fst = 1
    neg = true
  }
  for _, j := range sc.Bytes()[fst:] {
    ans = ans*10 + int(j-zero)
  }
  if neg == true {
    ans = -ans
  }
  return ans
}

//SEGMENT TREE FOR BITS
const Z int = -3000000

type SegmentTree struct {
  l, r, color int
  value       uint64
  left, right *SegmentTree
}

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

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

func CombineValues(val1 uint64, val2 uint64) uint64 { return val1 + val2 }

func (tree *SegmentTree) PaintedSegmentValue(CL int) uint64 { // XOR OPERATION
  if CL == 0 {
    return tree.value
  } else {
    return -tree.value + uint64(tree.r-tree.l+1)
  }
}

func CombineColors(cl1 int, cl2 int) int { return cl1 ^ cl2 }

func Init(L int, R int, data []int) *SegmentTree {
  res := new(SegmentTree)
  res.l = L
  res.r = R
  res.color = Z
  if L == R {
    res.value = uint64(data[L])
    res.left = nil
    res.right = nil
  } else {
    m := (L + R) >> 1
    res.left = Init(L, m, data)
    res.right = Init(m+1, R, data)
    res.value = CombineValues(res.left.value, res.right.value)
  }
  return res
}

func (tree *SegmentTree) GetValue(L int, R int, cl int) uint64 {
  if L > R {
    return 0
  }
  cl2 := CombineColors(tree.color, cl)
  m := (tree.l + tree.r) >> 1
  if L == tree.l && R == tree.r {
    if cl2 == Z {
      return tree.value
    }
    return tree.PaintedSegmentValue(cl2)
  }
  return CombineValues(tree.left.GetValue(L, Min(R, m), cl2),
    tree.right.GetValue(Max(L, m+1), R, cl2))
}

func (tree *SegmentTree) Paint(L int, R int, CL int) {
  if tree.l > R || L > tree.r || R < tree.l {
    return
  }
  if tree.l == L && tree.r == R {
    tree.color = CombineColors(tree.color, CL)
  } else {
    if tree.color != Z && tree.left != nil && tree.right != nil { //push
      tree.left.color = CombineColors(tree.left.color, tree.color)
      tree.right.color = CombineColors(tree.right.color, tree.color)
      tree.color = Z
    }
    m := (tree.l + tree.r) >> 1
    tree.left.Paint(L, Min(R, m), CL)
    tree.right.Paint(Max(L, m+1), R, CL)
    var val1, val2 uint64 = 0, 0
    if tree.left.color == Z {
      val1 = tree.left.value
    } else {
      val1 = tree.left.PaintedSegmentValue(tree.left.color)
    }
    if tree.right.color == Z {
      val2 = tree.right.value
    } else {
      val2 = tree.right.PaintedSegmentValue(tree.right.color)
    }
    tree.value = CombineValues(val1, val2)
  }
}

//END SEGMENT TREE

func main() {

  w = bufio.NewWriter(os.Stdout)
  sc = bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  n := nextInt()
  bits := make([][]int, 20)
  for i := 0; i < 20; i++ {
    bits[i] = make([]int, n)
  }
  trees := make([]*SegmentTree, 20)
  for i := 0; i < n; i++ {
    x := nextInt()
    for j := uint(0); j < 20; j++ {
      if ((1 << j) & x) > 0 {
        bits[j][i] = 1
      }
    }
  }
  for i := 0; i < 20; i++ {
    trees[i] = Init(0, n-1, bits[i])
  }
  m := nextInt()
  for i := 0; i < m; i++ {
    t, l, r := nextInt(), nextInt()-1, nextInt()-1
    if t == 1 {
      var ans uint64 = 0
      for j := uint(0); j < 20; j++ {
        //w.WriteString(strconv.FormatUint(trees[j].GetValue(l, r, 0), 10))
        //w.WriteByte(' ')
        ans += trees[j].GetValue(l, r, 0) * (1 << j)
      }
      w.WriteString(strconv.FormatUint(ans, 10))
      w.WriteByte('\n')
    } else {
      x := nextInt()
      for j := uint(0); j < 20; j++ {
        if ((1 << j) & x) > 0 {
          trees[j].Paint(l, r, 1)
        }
      }
    }
  }
  w.Flush()
  //YOU FORGOT TO FLUSH!
}


Naruto has sneaked into the Orochimaru's lair and is now looking for Sasuke. There are $$$T$$$ rooms there. Every room has a door into it, each door can be described by the number $$$n$$$ of seals on it and their integer energies $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$. All energies $$$a_i$$$ are nonzero and do not exceed $$$100$$$ by absolute value. Also, $$$n$$$ is even.In order to open a door, Naruto must find such $$$n$$$ seals with integer energies $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ that the following equality holds: $$$a_{1} \cdot b_{1} + a_{2} \cdot b_{2} + ... + a_{n} \cdot b_{n} = 0$$$. All $$$b_i$$$ must be nonzero as well as $$$a_i$$$ are, and also must not exceed $$$100$$$ by absolute value. Please find required seals for every room there.

The first line contains the only integer $$$T$$$ ($$$1 \leq T \leq 1000$$$) standing for the number of rooms in the Orochimaru's lair. The other lines contain descriptions of the doors. Each description starts with the line containing the only even integer $$$n$$$ ($$$2 \leq n \leq 100$$$) denoting the number of seals. The following line contains the space separated sequence of nonzero integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$|a_{i}| \leq 100$$$, $$$a_{i} \neq 0$$$) denoting the energies of seals.

For each door print a space separated sequence of nonzero integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$|b_{i}| \leq 100$$$, $$$b_{i} \neq 0$$$) denoting the seals that can open the door. If there are multiple valid answers, print any. It can be proven that at least one answer always exists.

NoteFor the first door Naruto can use energies $$$[-100, 1]$$$. The required equality does indeed hold: $$$1 \cdot (-100) + 100 \cdot 1 = 0$$$.For the second door Naruto can use, for example, energies $$$[1, 1, 1, -1]$$$. The required equality also holds: $$$1 \cdot 1 + 2 \cdot 1 + 3 \cdot 1 + 6 \cdot (-1) = 0$$$.

package main

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

func main() {
	var T int
	var results [][]int

	fmt.Scanf("%d\n", &T)
	in := bufio.NewReader(os.Stdin)
	for i:=0; i<T*2; i++ {
		line, err := in.ReadString('\n')
		line = strings.Replace(line, "\r", "", -1)
		line = strings.Replace(line, "\n", "", -1)
		strs := strings.Split(line, " ")
		nums := make([]int, len(strs))
		if len(strs) > 1 {
			for i, str := range strs {
				if nums[i], err = strconv.Atoi(str); err != nil {
					log.Fatal(err)
				}
			}
			results = append(results, nums)
		}
	}
	for il:=0; il <len(results); il++{
		rsd:=fn(results[il])
		for i:=0; i <len(rsd); i++{
			fmt.Printf("%d ",rsd[i])
		}
		fmt.Print("\n")
	}
}

func fn(a []int) []int{
	var b = make([]int, len(a))
	for i:=0; i<len(a)-1;i=i+2{
		b[i] = a[i+1]
		b[i+1] = -a[i]
	}
	return b
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	r := make([]string, n)
	for i := 0; i < n; i++ {
		var nn int
		fmt.Scan(&nn)
		arr := make([]int, nn)
		for j := 0; j < nn; j++ {
			fmt.Scan(&arr[j])
		}
		r = append(r, strings.Join(calculate(arr), " "))
	}
	for _, v := range r {
		fmt.Println(v)
	}
}
func calculate(a []int) []string {
	r := make([]string, len(a))
	for i := 0; i < len(a); i+=2 {
		r[i] = strconv.Itoa(-a[i+1])
	}
	for i := 1; i < len(a); i+=2 {
		r[i] = strconv.Itoa(a[i-1])
	}
	return r
}

package main

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

func main() {
	io := bufio.NewReader(os.Stdin)
	var T, n, a1, a2 int

	fmt.Fscan(io, &T)
	for ; T > 0; T-- {
		fmt.Fscan(io, &n)
		for ; n>0; n-=2 {
			fmt.Fscan(io, &a1, &a2)
			fmt.Printf("%d %d ", a2, -a1)
		}
		fmt.Println()
	}

}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		b := solve(n, a)
		for j := 0; j < n; j++ {
			if j > 0 {
				print(" ")
			}
			printf("%d", b[j])
		}
		println()
	}
}

func solve(n int, a []int) []int {
	b := make([]int, n)
	for i := 0; i < n/2; i++ {
		b[i*2], b[i*2+1] = -a[i*2+1], a[i*2]
	}
	return b
}

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

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

package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

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

func main() {
	for tt := NextInt(); tt > 0; tt-- {
		n := NextInt()
		for i := 0; i < n / 2; i++ {
			a, b := NextInt(), NextInt()
			fmt.Printf("%d %d ", -b, a)
		}
		fmt.Println()
	}
}

package main

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

type kv struct {
	Key   int
	Value int
}

func main() {
	//rd, _ := os.Open("input")
	io := bufio.NewReader(os.Stdin)

	var t, n, a1, a2 int

	fmt.Fscan(io, &t)
	for ; t > 0; t-- {
		fmt.Fscan(io, &n)
		for i := 0; i < n/2; i++ {
			fmt.Fscan(io, &a1, &a2)
			fmt.Printf("%d %d ", -a2, a1)
		}
		fmt.Println()
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for t > 0 {
		t--
		func() {
			n := getNextInt(scanner)
			aa := make([]int, n)
			for i := 0; i < n; i++ {
				aa[i] = getNextInt(scanner)
			}
			bb := make([]int, n)
			for i := 0; i < n>>1; i++ {
				bb[i] = aa[n-1-i]
				bb[n-1-i] = -aa[i] * bb[i] / aa[n-1-i]
			}
			sep := ""
			for i := 0; i < n; i++ {
				fmt.Fprintf(writer, "%s%d", sep, bb[i])
				sep = " "
			}
			fmt.Fprintln(writer, "")
		}()
	}
}

package main

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

func main() {
	var T int
	var res [][]int
	fmt.Scanf("%d\n", &T)
	for i:=0; i<T; i++{

		in := bufio.NewReader(os.Stdin)
		prom, _ := in.ReadString('\n')

		le, _ := strconv.Atoi(strings.Replace(prom, "\n", "", -1))
		var mas = make([]int, le)
		prom, _ = in.ReadString('\n')
		promn := strings.Split(strings.Replace(prom, "\n", "", -1), " ")
		for g:=0; g<le; g++{
			mas[g] , _= strconv.Atoi(promn[g])
		}
		res=append(res, mas)
	}

	for il:=0; il <len(res); il++{
		rsd:=fn(res[il])
		for i:=0; i <len(rsd); i++{
			fmt.Printf("%d ",rsd[i])
		}
		fmt.Print("\n")
	}
}

func fn(a []int) []int{
	var b = make([]int, len(a))
	for i:=0; i<len(a)-1;{
		if a[i+1] % a[i] == 0{
			b[i] = a[i+1] / a[i]
			b[i+1] = -1
			i=i+2
		}
	}
	return b
}

package main

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

func main() {
	var T int
	var res [][]int
	fmt.Scanf("%d\n", &T)
	for i:=0; i<T; i++{
		var le = 0
		fmt.Scanf("%d\n", &le)
		var mas = make([]int, le)
		in := bufio.NewReader(os.Stdin)
		prom, _ := in.ReadString('\n')
		promn := strings.Split(strings.Replace(prom, "\n", "", -1), " ")
		for g:=0; g<le; g++{
			mas[g] , _= strconv.Atoi(promn[g])
		}
		res=append(res, mas)
	}

	for il:=0; il <len(res); il++{
		rsd:=fn(res[il])
		for i:=0; i <len(rsd); i++{
			fmt.Printf("%d ",rsd[i])
		}
		fmt.Print("\n")
	}
}

func fn(a []int) []int{
	var b = make([]int, len(a))
	for i:=0; i<len(a)-1;{
		if a[i+1] % a[i] == 0{
			b[i] = a[i+1] / a[i]
			b[i+1] = -1
			i=i+2
		}
	}
	return b
}

package main

import (
	"fmt"
)

func main() {
	var T, n, a1, a2 int

	fmt.Scan(&T)
	for i:=0; i<T; i++ {
		fmt.Scan(&n)
		for j:=0; j<n/2; j++ {
			fmt.Scan(&a1)
			fmt.Scan(&a2)
			fmt.Printf("%d -%d ", a2, a1)
		}
		fmt.Println()
	}

}

package main

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

func main() {
	defer _w.Flush()
	t := ReadInt()
	for i := 0; i < t; i++ {
		n := ReadInt()
		a := ReadInts(n)
		b := solve(n, a)
		for j := 0; j < n; j++ {
			if j > 0 {
				print(" ")
			}
			printf("%d", b[j])
		}
		println()
	}
}

func solve(n int, a []int) []int {
	s := 0
	for i := 0; i < n; i++ {
		s += a[i]
	}

	s1 := s - a[0]
	for b1 := -100; b1 <= 100; b1++ {
		if b1*a[0]%s1 == 0 {
			b := -b1 * a[0] / s1
			ans := make([]int, 0)
			ans = append(ans, b1)
			for i := 0; i < n-1; i++ {
				ans = append(ans, b)
			}
			return ans
		}
	}
	return nil
}

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

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

package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

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

func main() {
	for tt := NextInt(); tt > 0; tt-- {
		n := NextInt()
		for i := 0; i < n / 2; i++ {
			a, b := NextInt(), NextInt()
			fmt.Printf("%d %d ", -b, -a)
		}
		fmt.Println()
	}
}