You are given $$$n$$$ rectangles, each of height $$$1$$$. Each rectangle's width is a power of $$$2$$$ (i. e. it can be represented as $$$2^x$$$ for some non-negative integer $$$x$$$). You are also given a two-dimensional box of width $$$W$$$. Note that $$$W$$$ may or may not be a power of $$$2$$$. Moreover, $$$W$$$ is at least as large as the width of the largest rectangle.You have to find the smallest height of this box, such that it is able to fit all the given rectangles. It is allowed to have some empty space left in this box after fitting all the rectangles.You cannot rotate the given rectangles to make them fit into the box. Moreover, any two distinct rectangles must not overlap, i. e., any two distinct rectangles must have zero intersection area.See notes for visual explanation of sample input.

The first line of input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^3$$$) — the number of test cases. Each test case consists of two lines. For each test case:  the first line contains two integers $$$n$$$ ($$$1 \le n \le 10^5$$$) and $$$W$$$ ($$$1 \le W \le 10^9$$$); the second line contains $$$n$$$ integers $$$w_1, w_2, \dots, w_n$$$ ($$$1 \le w_i \le 10^6$$$), where $$$w_i$$$ is the width of the $$$i$$$-th rectangle. Each $$$w_i$$$ is a power of $$$2$$$; additionally, $$$\max\limits_{i=1}^{n} w_i \le W$$$.  The sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

Output $$$t$$$ integers. The $$$i$$$-th integer should be equal to the answer to the $$$i$$$-th test case — the smallest height of the box.

NoteFor the first test case in the sample input, the following figure shows one way to fit the given five rectangles into the 2D box with minimum height:  In the figure above, the number inside each rectangle is its width. The width of the 2D box is $$$16$$$ (indicated with arrow below). The minimum height required for the 2D box in this case is $$$2$$$ (indicated on the left).In the second test case, you can have a minimum height of three by keeping two blocks (one each of widths eight and two) on each of the three levels.

package main

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

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

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var l int
	fmt.Scanf("%d\n", &l)
	for i := 0; i < l; i++ {
		m := make([]int, 20)
		var n, W int
		fmt.Fscan(in, &n, &W)
		for i := 0; i < n; i++ {
			var tp float64
			fmt.Fscan(in, &tp)
			m[int(math.Round(math.Log2(tp)))]++
		}
		fmt.Printf("%d\n", fn(W, m))
	}
}

func fn(W int, m []int) int {
	i := 0
	isnotnul := true
	for ; isnotnul; i++ {
		d := W
		for e := 19; e >= 0; e-- {
			itemWidth := int(math.Pow(2, float64(e)))
			if (m[e] > 0) && (d >= itemWidth) {
				m[e]--
				d = d - itemWidth
				e++
			}
		}
		isnotnul = false
		for e := 0; e < len(m); e++ {
			if m[e] > 0 {
				isnotnul = true
				break
			}
		}

	}

	return i
}

package main

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

//Box Fitting
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
var scanner *bufio.Scanner = bufio.NewScanner(reader)

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

func boxFitting( W int, N int) {
	slots := make([]int, 32)
	minHeight := 0
	for x :=0 ; x< N ;x ++ {
		var v int
		if x != N-1 {
			scanf("%d", &v)
		} else {
			scanf("%d\n", &v)
		}
		slots[int(math.Log2(float64(v)))] += 1
	}
	var cur int
	for N> 0 {
		cur = W
		for i := 31; i >= 0; i-- {
			for slots[i] > 0 && cur >= (1<<i) {
				slots[i] -=1
				N -=1
				cur -= (1 << i)
			}
		}
		minHeight += 1
	}
	fmt.Println(minHeight)
}

func main() {

	var testCases int
	scanf("%d\n", &testCases)
	for i:=0 ; i< testCases; i++ {
		var N int
		var W int
		scanf("%d %d\n", &N, &W)
		boxFitting( W , N)

	}
}

package main

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

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

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = (n * 10) + int(v-'0')
	}
	return
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (a Pairs) Len() int           { return len(a) }
func (a Pairs) Less(i, j int) bool { return a[i].a < a[j].a }
func (a Pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	defer writer.Flush()

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

	for t > 0 {
		var n, w, width int
		scanf("%d %d\n", &n, &w)
		count := make([]int, 20)
		for i := 0; i < n; i++ {
			if i == n-1 {
				scanf("%d\n", &width)
			} else {
				scanf("%d ", &width)
			}
			count[int(math.Log2(float64(width)))]++
		}
		height, spaceLeft := 1, w
		for i := 0; i < n; i++ {
			largest := -1
			for size := 19; size >= 0; size-- {
				if count[size] > 0 && ((1 << size) <= spaceLeft) {
					largest = size
					break
				}
			}
			if largest == -1 {
				spaceLeft = w
				height++
				for size := 19; size >= 0; size-- {
					if count[size] > 0 && ((1 << size) <= spaceLeft) {
						largest = size
						break
					}
				}
			}

			count[largest] -= 1
			spaceLeft -= (1 << largest)
		}
		printf("%d\n", height)
		t--
	}

}

package main

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

var in = bufio.NewReader(os.Stdin)
var a []int

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		a = make([]int, 20)
		var n, w int
		fmt.Fscan(in, &n, &w)
		for i := 0; i < n; i++ {
			var tp float64
			fmt.Fscan(in, &tp)
			a[int(math.Round(math.Log2(tp)))]++
		}
		rs := 0
		tp := 0
		for !done() {
			if tp == 0 {
				rs++
				tp = w
			}
			tp = fit(tp)
		}
		fmt.Println(rs)
	}
}

func fit(x int) int {
	for i := 19; i >= 0; i-- {
		tp := int(math.Pow(2, float64(i)))
		if a[i] > 0 && x >= tp {
			a[i]--
			return x - tp
		}
	}
	return 0
}

func done() bool {
	for i := 0; i < 20; i++ {
		if a[i] > 0 {
			return false
		}
	}
	return true
}

package main

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

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

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

		m := make([]int, 32)
		for i := 0; i < n; i++ {
			var v uint
			fmt.Fscan(in, &v)

			m[bits.Len(v)-1]++
		}

		z := n
		var tot int
		for z > 0 {
			k := w
			l := bits.Len(uint(k)) - 1
			x := 1 << l
			for i := l; i >= 0; i-- {
				if k <= 0 {
					break
				}

				d := min(m[i], k/x)
				m[i] -= d
				z -= d
				k -= d * x
				x /= 2
			}

			tot++
		}

		fmt.Fprintln(out, tot)
	}
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}

func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}

func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}

func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}

func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

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

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

		count := make([]int, 32)
		for i := 0; i < N; i++ {
			count[int(math.Log2(float64(arr[i])+1e-5))]++
		}
		ans := 0
		remWidth := 0
		remBox := N

		for remBox > 0 {
			ans++
			remWidth = W
			for i := 31; i >= 0; i-- {
				for count[i] > 0 && remWidth >= (1<<i) {
					count[i]--
					remWidth -= (1 << i)
					remBox--
				}
			}
		}

		fmt.Fprintln(wr, ans)
	}

}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n, W := readTwoNums(reader)
		boxes := readNNums(reader, n)
		res := solve(W, boxes)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(W int, boxes []int) int {
	sort.Ints(boxes)
	reverse(boxes)
	n := len(boxes)
	stack := make([]int, n)

	for i := 0; i < n; i++ {
		stack[i] = W
	}

	for i := 0; i < n; i++ {
		cur := boxes[i]
		j := sort.Search(n, func(j int) bool {
			return stack[j] >= cur
		})
		stack[j] -= cur
	}
	j := sort.Search(n, func(j int) bool {
		return stack[j] == W
	})

	return j
}

func reverse(arr []int) {
	for i, j := 0, len(arr)-1; i < j; i, j = i+1, j-1 {
		arr[i], arr[j] = arr[j], arr[i]
	}
}

package main

import (
	"fmt"
	"sort"
)

//Box Fitting

func boxFitting(listOfSizes []int , W int, N int) int {
	sort.Slice(listOfSizes, func(i, j int) bool {
		return listOfSizes[i] > listOfSizes[j]
	})
	slabs := []int{W}
	minHeight := 1
	for _, weight := range listOfSizes {
		if slabsX, flag := processExistingSlab(slabs, weight); !flag {
			if slabW := W - weight; slabW > 0 {
				slabs = append(slabs, slabW)
			}
			minHeight += 1
		} else {
			slabs = slabsX
		}
	}
	return minHeight
}

func processExistingSlab(slabs []int, weight int) ([]int,bool) {
	for slab_index := 0; slab_index < len(slabs); slab_index++ {
		if slabs[slab_index] >= weight {
			slabs[slab_index] -= weight
			return slabs, true

		}
	}
	return slabs, false
}

func main() {
	var testCases int
	fmt.Scanf("%d\n", &testCases)
	for i:=0 ; i< testCases; i++ {
		var N int
		var W int
		var numbs []int
		fmt.Scanf("%d %d\n", &N, &W)
		for x :=0 ; x< N;x ++ {
			var v int
			fmt.Scanf("%d", &v)
			numbs = append(numbs, v)
		}

		fmt.Println(boxFitting(numbs, W , N))
	}
}

package main

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

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

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = (n * 10) + int(v-'0')
	}
	return
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (a Pairs) Len() int           { return len(a) }
func (a Pairs) Less(i, j int) bool { return a[i].a < a[j].a }
func (a Pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	defer writer.Flush()

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

	for t > 0 {
		var n, w, width int
		scanf("%d %d\n", &n, &w)
		count := make([]int, 20)
		for i := 0; i < n; i++ {
			if i == n-1 {
				scanf("%d\n", &width)
			} else {
				scanf("%d ", &width)
			}
			count[int(math.Log(float64(width)))]++
		}
		height, spaceLeft := 1, w
		for i := 0; i < n; i++ {
			largest := -1
			for size := 19; size >= 0; size-- {
				if count[size] != 0 && ((1 << size) <= spaceLeft) {
					largest = size
					break
				}
			}
			if largest == -1 {
				spaceLeft = w
				height++
				for size := 19; size >= 0; size-- {
					if count[size] != 0 && ((1 << size) <= spaceLeft) {
						largest = size
						break
					}
				}
			}

			count[largest] -= 1
			spaceLeft -= (1 << largest)
		}
		printf("%d\n", height+1)
		t--
	}

}

package main

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

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

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = (n * 10) + int(v-'0')
	}
	return
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (a Pairs) Len() int           { return len(a) }
func (a Pairs) Less(i, j int) bool { return a[i].a < a[j].a }
func (a Pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	defer writer.Flush()

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

	for t > 0 {
		var n, w int
		scanf("%d %d\n", &n, &w)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			if i == n-1 {
				scanf("%d\n", &arr[i])
			} else {
				scanf("%d ", &arr[i])
			}
		}
		sort.Ints(arr)
		height, width := 1, 0
		for i := n - 1; i >= 0; i-- {
			width += arr[i]
			if width > w {
				width = 0
				height++
			}
		}
		printf("%d\n", height)
		t--
	}

}

package main

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

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

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = (n * 10) + int(v-'0')
	}
	return
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (a Pairs) Len() int           { return len(a) }
func (a Pairs) Less(i, j int) bool { return a[i].a < a[j].a }
func (a Pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	defer writer.Flush()

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

	for t > 0 {
		var n, w int
		scanf("%d %d\n", &n, &w)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			if i == n-1 {
				scanf("%d\n", &arr[i])
			} else {
				scanf("%d ", &arr[i])
			}
		}
		sort.Ints(arr)
		height, width := 1, 0
		for i := 0; i < n; i++ {
			width += arr[i]
			if width > w {
				width = 0
				height++
			}
		}
		printf("%d\n", height)
		t--
	}

}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		for ; ; n++ {
			s := calSum(n)
			j := s
			for j = s; j >= 1; j-- {
				if n%j == 0 && s%j == 0 {
					break
				}
			}
			if j > 1 {
				fmt.Println(n)
				break
			}
		}
	}
}

func calSum(n int) int {
	s := 0
	for n > 0 {
		s += n % 10
		n /= 10
	}
	return s
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}

func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}

func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}

func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}

func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

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

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.nextInt()
		W := sc.nextInt64()
		arr := sc.nextInt64s(N)

		sum := int64(0)
		for i := 0; i < N; i++ {
			sum += arr[i]
		}
		ans := (sum + W - 1) / W
		fmt.Fprintln(wr, ans)
	}

}


The legend of the foundation of Vectorland talks of two integers $$$x$$$ and $$$y$$$. Centuries ago, the array king placed two markers at points $$$|x|$$$ and $$$|y|$$$ on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers at points $$$|x - y|$$$ and $$$|x + y|$$$ and conquered all the land in between (including the endpoints), which he declared to be Vectorland. He did so in such a way that the land of Arrayland was completely inside (including the endpoints) the land of Vectorland.Here $$$|z|$$$ denotes the absolute value of $$$z$$$.Now, Jose is stuck on a question of his history exam: "What are the values of $$$x$$$ and $$$y$$$?" Jose doesn't know the answer, but he believes he has narrowed the possible answers down to $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. Now, he wants to know the number of unordered pairs formed by two different elements from these $$$n$$$ integers such that the legend could be true if $$$x$$$ and $$$y$$$ were equal to these two values. Note that it is possible that Jose is wrong, and that no pairs could possibly make the legend true.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$)  — the number of choices. The second line contains $$$n$$$ pairwise distinct integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the choices Jose is considering.

Print a single integer number — the number of unordered pairs $$$\{x, y\}$$$ formed by different numbers from Jose's choices that could make the legend true.

NoteConsider the first sample. For the pair $$$\{2, 5\}$$$, the situation looks as follows, with the Arrayland markers at $$$|2| = 2$$$ and $$$|5| = 5$$$, while the Vectorland markers are located at $$$|2 - 5| = 3$$$ and $$$|2 + 5| = 7$$$:  The legend is not true in this case, because the interval $$$[2, 3]$$$ is not conquered by Vectorland. For the pair $$$\{5, -3\}$$$ the situation looks as follows, with Arrayland consisting of the interval $$$[3, 5]$$$ and Vectorland consisting of the interval $$$[2, 8]$$$:  As Vectorland completely contains Arrayland, the legend is true. It can also be shown that the legend is true for the pair $$$\{2, -3\}$$$, for a total of two pairs.In the second sample, the only pair is $$$\{3, 6\}$$$, and the situation looks as follows:  Note that even though Arrayland and Vectorland share $$$3$$$ as endpoint, we still consider Arrayland to be completely inside of Vectorland.

// http://codeforces.com/contest/1166/problem/C

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	fmt.Fprintln(out, Solve(n, a))
}

func Solve(n int, a []int) int64 {
	b := make([]int, n)
	for i := int(0); i < n; i++ {
		if a[i] < 0 {
			b[i] = -a[i]
		} else {
			b[i] = a[i]
		}
	}
	sort.Ints(b)

	cnt := int64(0)
	for l := int(0); l < n; l++ {
		r := BinSearch(b, l, b[l]*2)
		cnt += int64(r - l)
	}

	return cnt
}

func BinSearch(a []int, l, n int) int {
	l = l - 1
	r := len(a)
	for r-l > 1 {
		m := l + (r-l)/2
		if a[m] <= n {
			l = m
		} else {
			r = m
		}
	}
	return l
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())
		if a[i] < 0 {
			a[i] = -a[i]
		}
	}
	sort.Ints(a)
	ans := int64(0)
	for i, j := 0, 0; i < n; i++ {
		for j < i && a[j] * 2 < a[i] {
			j++
		}
		ans += int64(i - j)
	}
	fmt.Print(ans)
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

func ReadInt() int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := ReadInt()
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
		if arr[i] < 0 {
			arr[i] *= -1
		}
	}

	sort.Ints(arr)

	j := 0
	var ct int64
	for i := 1; i < n; i++ {
		for 2*arr[j] < arr[i] && j < i {
			j++
		}
		ct += int64(i - j)
	}
	fmt.Println(ct)
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1166/C

package main

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

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

func valid(x int, y int) bool {
	return y <= 2*x && x <= 2*y
}

func search(i, n, start, end int, a []int) int {
	if start < 0 || end > n-1 || start > end {
		return 0
	}
	m := (start + end + 1) / 2
	if valid(a[m], a[i]) {
		if start == end {
			return start - i
		}
		return search(i, n, m, end, a)
	}
	return search(i, n, start, m-1, a)
}

func Solve(n int, a []int) int64 {
	for i := 0; i < n; i++ {
		a[i] = abs(a[i])
	}
	sort.Ints(a)
	ans := int64(0)
	for i, _ := range a {
		ans += int64(search(i, n, i+1, n-1, a))
	}
	return ans
}

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

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

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

// http://codeforces.com/contest/1166/problem/C

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	fmt.Fprintln(out, Solve(n, a))
}

func Solve(n int, a []int) int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		if a [i] < 0 {
			b[i] = -a[i]
		} else {
			b[i] = a[i]
		}
	}
	sort.Ints(b)

	cnt := 0
	for l := 0; l < n; l++ {
		r := BinSearch(b, l, b[l]*2)
		cnt += r - l
	}

	return cnt
}

func BinSearch(a []int, l, n int) int {
	l = l  -  1
	r := len(a)
	for r-l > 1 {
		m := l + (r-l)/2
		if a[m] <= n {
			l = m
		} else {
			r = m
		}
	}
	return l
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

func ReadInt() int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := ReadInt()
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
		if arr[i] < 0 {
			arr[i] *= -1
		}
	}

	sort.Ints(arr)

	j := 0
	ct := 0
	for i := 1; i < n; i++ {
		for 2*arr[j] < arr[i] && j < n {
			j++
		}
		ct += i - j
	}

	fmt.Println(ct)
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1166/C

package main

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

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

func valid(x int, y int) bool {
	return y <= 2*x && x <= 2*y
}

func search(i, n, start, end int, a []int) int {
	if start < 0 || end > n-1 || start > end {
		return 0
	}
	m := (start + end + 1) / 2
	if valid(a[m], a[i]) {
		if start == end {
			return start - i
		}
		return search(i, n, m, end, a)
	}
	return search(i, n, start, m-1, a)
}

func Solve(n int, a []int) int {
	for i := 0; i < n; i++ {
		a[i] = abs(a[i])
	}
	sort.Ints(a)
	ans := 0
	for i, _ := range a {
		ans += search(i, n, i+1, n-1, a)
	}
	return ans
}

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

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

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


Fox Ciel is playing a card game with her friend Jiro.Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack.Now is Ciel's battle phase, Ciel can do the following operation many times:  Choose one of her cards X. This card mustn't be chosen before.  If Jiro has no alive cards at that moment, he gets the damage equal to (X's strength). Otherwise, Ciel needs to choose one Jiro's alive card Y, then:   If Y's position is Attack, then (X's strength)  ≥  (Y's strength) must hold. After this attack, card Y dies, and Jiro gets the damage equal to (X's strength) - (Y's strength).  If Y's position is Defense, then (X's strength)  >  (Y's strength) must hold. After this attack, card Y dies, but Jiro gets no damage.  Ciel can end her battle phase at any moment (so, she can use not all her cards). Help the Fox to calculate the maximal sum of damage Jiro can get.

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of cards Jiro and Ciel have. Each of the next n lines contains a string position and an integer strength (0 ≤ strength ≤ 8000) — the position and strength of Jiro's current card. Position is the string "ATK" for attack, and the string "DEF" for defense. Each of the next m lines contains an integer strength (0 ≤ strength ≤ 8000) — the strength of Ciel's current card.

Output an integer: the maximal damage Jiro can get.

NoteIn the first test case, Ciel has 3 cards with same strength. The best strategy is as follows. First she uses one of these 3 cards to attack "ATK 2000" card first, this attack destroys that card and Jiro gets 2500 - 2000 = 500 damage. Then she uses the second card to destroy the "DEF 1700" card. Jiro doesn't get damage that time. Now Jiro has no cards so she can use the third card to attack and Jiro gets 2500 damage. So the answer is 500 + 2500 = 3000.In the second test case, she should use the "1001" card to attack the "ATK 100" card, then use the "101" card to attack the "ATK 10" card. Now Ciel still has cards but she can choose to end her battle phase. The total damage equals (1001 - 100) + (101 - 10) = 992.In the third test case note that she can destroy the "ATK 0" card by a card with strength equal to 0, but she can't destroy a "DEF 0" card with that card.

package main

import (
    "fmt"
    "sort"
)

var (
    n, m, i, j    int
    atk, def, fox []int
)

func killAll() int {
    var cp []int
    cp = append(cp, fox...)
    i := 0
    for j := 0; j < len(def); j++ {
        for i < len(cp) {
            if cp[i] > def[j] {
                cp[i] = 0
                break
            }
            i += 1
        }
        if i == len(cp) {
            return 0
        }
    }
    ans := 0
    i = 0
    for j := 0; j < len(atk); j++ {
        for i < len(cp) {
            if cp[i] >= atk[j] {
                ans += cp[i] - atk[j]
                cp[i] = 0
                break
            }
            i += 1
        }
        if i == len(cp) {
            return 0
        }
    }
    for i := 0; i < len(cp); i++ {
        ans += cp[i]
    }
    return ans
}

func onlyatk() int {
    ans := 0

    for i := 0; i < len(atk); i++ {
        if i >= len(fox) {
            return ans
        }
        now := 0
        for j := 0; j <= i; j++ {
            now += fox[len(fox)-j-1] - atk[j]
        }
        if now > ans {
            ans = now
        }
    }
    return ans
}

func main() {
    fmt.Scan(&n, &m)
    var temp string
    for i := 0; i < n; i++ {
        fmt.Scan(&temp, &j)
        if temp == "ATK" {
            atk = append(atk, j)
        } else {
            def = append(def, j)
        }
    }
    for i := 0; i < m; i++ {
        fmt.Scan(&j)
        fox = append(fox, j)
    }
    sort.Ints(def)
    sort.Ints(atk)
    sort.Ints(fox)
    a := killAll()
    b := onlyatk()
    if a>b {
        fmt.Println(a)
    } else {
        fmt.Println(b)
    }
}


Vupsen and Pupsen were gifted an integer array. Since Vupsen doesn't like the number $$$0$$$, he threw away all numbers equal to $$$0$$$ from the array. As a result, he got an array $$$a$$$ of length $$$n$$$.Pupsen, on the contrary, likes the number $$$0$$$ and he got upset when he saw the array without zeroes. To cheer Pupsen up, Vupsen decided to come up with another array $$$b$$$ of length $$$n$$$ such that $$$\sum_{i=1}^{n}a_i \cdot b_i=0$$$. Since Vupsen doesn't like number $$$0$$$, the array $$$b$$$ must not contain numbers equal to $$$0$$$. Also, the numbers in that array must not be huge, so the sum of their absolute values cannot exceed $$$10^9$$$. Please help Vupsen to find any such array $$$b$$$!

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$2 \cdot t$$$ lines contain the description of test cases. The description of each test case consists of two lines. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^4 \le a_i \le 10^4$$$, $$$a_i \neq 0$$$) — the elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ — elements of the array $$$b$$$ ($$$|b_1|+|b_2|+\ldots +|b_n| \le 10^9$$$, $$$b_i \neq 0$$$, $$$\sum_{i=1}^{n}a_i \cdot b_i=0$$$). It can be shown that the answer always exists.

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

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

var t int

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

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

		ARR := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(input, &ARR[i])

		}
		if n%2 == 0 {
			q := n / 2
			for i := n; i > 0; i-- {
				if i > q {
					fmt.Println(-ARR[i])
				} else {
					fmt.Println(ARR[i])

				}
			}
		} else {
			first := ARR[1]
			Midd := ARR[2]
			Last := ARR[3]
			var F, M, L int
			Pos := 0
			Neg := 0
			if first > 0 {
				Pos++
			} else {
				Neg++
			}
			if Midd > 0 {
				Pos++
			} else {
				Neg++
			}
			if Last > 0 {
				Pos++
			} else {
				Neg++
			}
			if Pos*Neg != 0 {
				if ABS(first) == ABS(Midd) && ABS(Midd) == ABS(Last) {
					if first == Midd {
						if Midd == Last {
							F = -1
							M = -1
							L = 2
						} else {
							F = 1
							M = 1
							L = 2
						}
					} else {
						if first == Last {
							F = 1
							L = 1
							M = 2
						} else {
							M = 1
							L = 1
							F = 2
						}
					}
				} else {
					One := first + Midd
					Two := Midd + Last
					Thr := first + Last
					l := 0
					if One != 0 && ABS(One) <= 10000 {
						F = Last
						M = Last
						L = -One
						l = 1
					}

					if Two != 0 && ABS(Two) <= 10000 && l == 0 {
						F = -Two
						M = first
						L = first
						l = 1
					}
					if Thr != 0 && ABS(Thr) <= 10000 && l == 0 {
						F = Midd
						M = -Thr
						L = Midd
					}

				}
			} else {
				if ABS(first) == ABS(Midd) && ABS(Midd) == ABS(Last) {
					F = -1
					M = -1
					L = 2
				} else {
					One := first - Midd
					Two := Midd - Last
					Thr := first - Last
					l := 0
					if One != 0 && ABS(One) <= 10000 {
						F = -Last
						M = Last
						L = One
						l = 1
					}

					if Two != 0 && ABS(Two) <= 10000 && l == 0 {
						F = Two
						M = -first
						L = first
						l = 1
					}
					if Thr != 0 && ABS(Thr) <= 10000 && l == 0 {
						F = -Midd
						M = Thr
						L = Midd
					}

				}
			}

			fmt.Println(F)
			fmt.Println(M)
			fmt.Println(L)

			q := (n / 2) + 2

			for i := n; i > 3; i-- {
				if i > q {
					fmt.Println(-ARR[i])
				} else {
					fmt.Println(ARR[i])

				}
			}

		}

	}

}

package main

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

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

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

	var T, n int
	for fmt.Fscan(r, &T); T > 0; T-- {
		fmt.Fscan(r, &n)
		arr := make([]int64, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &arr[i])
		}

		res := make([]int64, n)
		if n%2 == 0 {
			for i := 0; i < n; i += 2 {
				if (arr[i] > 0 && arr[i+1] > 0) || (arr[i] < 0 && arr[i+1] < 0) {
					res[i] = arr[i+1]
					res[i+1] = -arr[i]
				} else {
					res[i] = -arr[i+1]
					res[i+1] = arr[i]
				}
			}
		} else {
			for i := 0; i < n-3; i += 2 {
				if (arr[i] > 0 && arr[i+1] > 0) || (arr[i] < 0 && arr[i+1] < 0) {
					res[i] = arr[i+1]
					res[i+1] = -arr[i]
				} else {
					res[i] = -arr[i+1]
					res[i+1] = arr[i]
				}
			}

			a, b := arr[n-3], arr[n-2]+arr[n-1]
			aIdx, bIdx, cIdx := n-3, n-2, n-1
			if a == 0 || b == 0 {
				a, b = arr[n-2] , arr[n-3]+arr[n-1]
				aIdx, bIdx, cIdx = n-2, n-3, n-1
				if a == 0 || b == 0 {
					a, b = arr[n-1] , arr[n-3]+arr[n-2]
					aIdx, bIdx, cIdx = n-1, n-3, n-2
				}
			}
			if (a > 0 && b > 0) || (a < 0 && b < 0) {
				res[aIdx] = b
				res[bIdx] = -a
				res[cIdx] = -a
			} else {
				res[aIdx] = -b
				res[bIdx] = a
				res[cIdx] = a
			}
		}
		for _, v := range res {
			fmt.Fprint(w, v, " ")
		}
		fmt.Fprintln(w)
	}
}

package main

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

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

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

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

func main() {
	var T int
	scanf("%d", &T)
	for t := 0; t < T; t++ {
		var n int
		scanf("\n%d\n", &n)
		arr := make([]int,n)
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}
		brr := make([]int, n)
		round := n / 2 * 2
		for i := 0; i < round; i += 2 {
			lcm := arr[i] * arr[i + 1] / gcd(arr[i], arr[i + 1])
			brr[i] -= lcm / arr[i]
			brr[i + 1] += lcm / arr[i + 1]
		}
		if n % 2 == 1 {
			lcm := arr[n - 1] * arr[n - 2] / gcd(arr[n - 1], arr[n - 2])
			if brr[n - 2] - lcm / arr[n - 2] != 0 {
				brr[n - 2] -= lcm / arr[n - 2]
				brr[n - 1] += lcm / arr[n - 1]
			} else {
				brr[n - 2] += lcm / arr[n - 2]
				brr[n - 1] -= lcm / arr[n - 1]
			}
		}
		for i := 0; i < n; i++ {
			fmt.Printf("%d ", brr[i])
		}
		fmt.Printf("\n")
	}
}

package main

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

var n int

var a []int

var w *bufio.Writer

func main() {

	r := bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		a = make([]int, n)

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

		solve()

	}
}

func solve() {
	//5 -2 10 -9 4
	//5* a1 + (-2) * a2 + 10 * a3 + (-9)*a4 + 4 * a5 == 0

	if n % 2 == 0 {
		for i := 0; i < n; i+=2 {
			g := GCD(a[i + 1], a[i])

			a1 := a[i + 1]/g
			a0 := a[i]/g

			fmt.Fprint(w, -a1)
			fmt.Fprint(w," ")
			fmt.Fprint(w, a0)
			fmt.Fprint(w," ")
		}
		fmt.Fprintln(w)
	 } else {
		for i := 0; i < n - 3; i+=2 {
			g := GCD(a[i + 1], a[i])

			a1 := a[i + 1]/g
			a0 := a[i]/g

			fmt.Fprint(w, -a1)
			fmt.Fprint(w," ")
			fmt.Fprint(w, a0)
			fmt.Fprint(w," ")
		}

		if a[n - 1] + a[n - 2] != 0 {
			d := a[n - 1] + a[n - 2]

			g := GCD(d, a[n - 3])

			a1 := d/g
			a0 := a[n - 3]/g

			fmt.Fprint(w, -a1)
			fmt.Fprint(w," ")
			fmt.Fprint(w, a0)
			fmt.Fprint(w," ")
			fmt.Fprint(w, a0)
			fmt.Fprint(w," ")
			fmt.Fprintln(w)

		} else if a[n - 1] + a[n - 3] != 0 {
			d := a[n - 1] + a[n - 3]

			g := GCD(d, a[n - 2])

			a1 := d/g
			a0 := a[n - 2]/g

			fmt.Fprint(w, a0)
			fmt.Fprint(w," ")
			fmt.Fprint(w, -a1)
			fmt.Fprint(w, " ")
			fmt.Fprint(w, a0)
			fmt.Fprint(w, " ")
			fmt.Fprintln(w)

		} else {
			d := a[n - 2] + a[n - 3]

			g := GCD(d, a[n - 1])

			a1 := d/g
			a0 := a[n - 1]/g

			fmt.Fprint(w, a0)
			fmt.Fprint(w," ")
			fmt.Fprint(w, a0)
			fmt.Fprint(w," ")
			fmt.Fprint(w, -a1)
			fmt.Fprint(w," ")
			fmt.Fprintln(w)

		}

	}
	w.Flush()

}

// greatest common divisor (GCD) via Euclidean algorithm
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

package main

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

func gcd(x, y int)int{
	for y>0{
		t := x%y
		x = y
		y = t
	}
	return x
}
func lcm(x, y int)int{
	return x*y/gcd(x,y)
}
func abs(x int)int{
	if x<0{
		return -x
	}
	return x
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n int
		fmt.Fscan(in,&n)
		a := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		ans := []int{}
		for i:=1;i<=n;i+=2{
			if n%2==1&&i==n{
				break
			}
			var x, y int
			if n%2==1&&i==n-2{
				if a[i]+a[i+2]!=0{
					y = a[i]+a[i+2]
					x = a[i+1]
					k := lcm(abs(x),abs(y))
					dx := k/abs(x)
					dy := k/abs(y)
					if x>0&&y>0{
						ans = append(ans,dy,-dx,dy)
					}
					if (x>0&&y<0)||(x<0&&y>0){
						ans = append(ans,dy,dx,dy)
					}
					if x<0&&y<0{
						ans = append(ans,dy,-dx,dy)
					}
				}else if a[i]+a[i+1]!=0{
					y = a[i]+a[i+1]
					x = a[i+2]
					k := lcm(abs(x),abs(y))
					dx := k/abs(x)
					dy := k/abs(y)
					if x>0&&y>0{
						ans = append(ans,dy,dy,-dx)
					}
					if (x>0&&y<0)||(x<0&&y>0){
						ans = append(ans,dy,dy,dx)
					}
					if x<0&&y<0{
						ans = append(ans,dy,dy,-dx)
					}
				}else{
					y=a[i+1]+a[i+2]
					x=a[i]
					k := lcm(abs(x),abs(y))
					dx := k/abs(x)
					dy := k/abs(y)
					if x>0&&y>0{
						ans = append(ans,-dx,dy,dy)
					}
					if (x>0&&y<0)||(x<0&&y>0){
						ans = append(ans,dx,dy,dy)
					}
					if x<0&&y<0{
						ans = append(ans,-dx,dy,dy)
					}
				}
				continue
			}else {
				x = a[i]
				y = a[i+1]
			}
			k := lcm(abs(x),abs(y))
			dx := k/abs(x)
			dy := k/abs(y)
			if x>0&&y>0{
				ans = append(ans,-dx,dy)
			}
			if (x>0&&y<0)||(x<0&&y>0){
				ans = append(ans,dx,dy)
			}
			if x<0&&y<0{
				ans = append(ans,-dx,dy)
			}
			if n%2==1&&i==n-2{
				ans = append(ans,dy)
			}
		}
		for i:=0;i<len(ans);i++{
			fmt.Fprintf(out,"%d ",ans[i])
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

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

func Ans(ARR []int) {
	if len(ARR) < 2 {
		return
	}
	if len(ARR) == 2 {
		fmt.Println(ARR[1])
		fmt.Println(-ARR[0])
	} else {
		if len(ARR) == 3 {
			first := ARR[0]
			Midd := ARR[1]
			Last := ARR[2]
			var F, M, L int
			Pos := 0
			Neg := 0
			if first > 0 {
				Pos++
			} else {
				Neg++
			}
			if Midd > 0 {
				Pos++
			} else {
				Neg++
			}
			if Last > 0 {
				Pos++
			} else {
				Neg++
			}
			if Pos*Neg != 0 {
				if ABS(first) == ABS(Midd) && ABS(Midd) == ABS(Last) {
					if first == Midd {
						if Midd == Last {
							F = -1
							M = -1
							L = 2
						} else {
							F = 1
							M = 1
							L = 2
						}
					} else {
						if first == Last {
							F = 1
							L = 1
							M = 2
						} else {
							M = 1
							L = 1
							F = 2
						}
					}
				} else {
					One := first + Midd
					Two := Midd + Last
					Thr := first + Last
					l := 0
					if One != 0 && ABS(One) <= 10000 {
						F = Last
						M = Last
						L = -One
						l = 1
					}

					if Two != 0 && ABS(Two) <= 10000 && l == 0 {
						F = -Two
						M = first
						L = first
						l = 1
					}
					if Thr != 0 && ABS(Thr) <= 10000 && l == 0 {
						F = Midd
						M = -Thr
						L = Midd
					}

				}
			} else {
				if ABS(first) == ABS(Midd) && ABS(Midd) == ABS(Last) {
					F = -1
					M = -1
					L = 2
				} else {
					One := first - Midd
					Two := Midd - Last
					Thr := first - Last
					l := 0
					if One != 0 && ABS(One) <= 10000 {
						F = -Last
						M = Last
						L = One
						l = 1
					}

					if Two != 0 && ABS(Two) <= 10000 && l == 0 {
						F = Two
						M = -first
						L = first
						l = 1
					}
					if Thr != 0 && ABS(Thr) <= 10000 && l == 0 {
						F = -Midd
						M = Thr
						L = Midd
					}

				}
			}

			fmt.Println(F)
			fmt.Println(M)
			fmt.Println(L)
		} else {
			Q := make([]int, 0)
			P := make([]int, 0)
			P = append(P, ARR[0], ARR[1], ARR[2])
			p := len(ARR)
			for i := 3; i < p; i++ {
				Q = append(Q, ARR[i])
			}
			Ans(P)
			Ans(Q)
		}
	}
}

var t int

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

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

		ARR := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARR[i])

		}
		Ans(ARR)

	}

}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

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

var t int

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

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

		ARR := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(input, &ARR[i])

		}
		if n%2 == 0 {
			q := n / 2
			for i := n; i > 0; i-- {
				if i > q {
					fmt.Println(-ARR[i])
				} else {
					fmt.Println(ARR[i])

				}
			}
		} else {
			first := ARR[1]
			Midd := ARR[2]
			Last := ARR[3]
			var F, M, L int

			if ABS(first) == ABS(Midd) && ABS(Midd) == ABS(Last) {
				if first == Midd {
					if Midd == Last {
						F = -1
						M = -1
						L = 2
					} else {
						F = 1
						M = 1
						L = 2
					}
				} else {
					if first == Last {
						F = 1
						L = 1
						M = 2
					} else {
						M = 1
						L = 1
						F = 2
					}
				}
			} else {
				One := first + Midd
				Two := Midd + Last
				Thr := first + Last
				if One != 0 && ABS(One) <= 10000 {
					F = Last
					M = Last
					L = -One
				} else {
					if Two != 0 && ABS(Two) <= 10000 {
						F = -Two
						M = first
						L = first
					} else {
						if Thr != 0 && ABS(Thr) <= 10000 {
							F = Midd
							M = -Thr
							L = Midd
						}
					}
				}
			}

			fmt.Println(F)
			fmt.Println(M)
			fmt.Println(L)

			q := (n / 2) + 2

			for i := n; i > 3; i-- {
				if i > q {
					fmt.Println(-ARR[i])
				} else {
					fmt.Println(ARR[i])

				}
			}

		}

	}

}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

var t int

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

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		Pos := 0
		Neg := 0
		ARR := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(input, &ARR[i])
			if ARR[i] < 0 {
				Neg++
			} else {
				Pos++
			}

		}
		if n%2 == 0 {
			q := n / 2
			for i := n; i > 0; i-- {
				if i > q {
					fmt.Println(-ARR[i])
				} else {
					fmt.Println(ARR[i])

				}
			}
		} else {
			first := ARR[1]
			Midd := ARR[2]
			Last := ARR[3]
			var F, M, L int

			if math.Abs(float64(first)) == math.Abs(float64(Midd)) && math.Abs(float64(Midd)) == math.Abs(float64(Last)) {
				if first == Midd {
					if Midd == Last {
						F = -1
						M = -1
						L = 2
					} else {
						F = 1
						M = 1
						L = 2
					}
				} else {
					if first == Last {
						F = 1
						L = 1
						M = 2
					} else {
						M = 1
						L = 1
						F = 2
					}
				}
			} else {
				One := first + Midd
				Two := Midd + Last
				Thr := Last + first
				if One != 0 && math.Abs(float64(One)) <= 10000 {
					F = Last
					M = Last
					L = -One
				} else {
					if Two != 0 && math.Abs(float64(Two)) <= 10000 {
						F = -Two
						M = first
						L = first
					} else {
						if Thr != 0 && math.Abs(float64(Thr)) <= 10000 {
							F = Midd
							M = -Thr
							L = Midd
						}
					}
				}
			}

			fmt.Println(F)
			fmt.Println(M)
			fmt.Println(L)

			q := (n / 2) + 2

			for i := n; i > 3; i-- {
				if i > q {
					fmt.Println(-ARR[i])
				} else {
					fmt.Println(ARR[i])

				}
			}

		}

	}

}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

var t int

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

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		Pos := 0
		Neg := 0
		ARR := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(input, &ARR[i])
			if ARR[i] < 0 {
				Neg++
			} else {
				Pos++
			}

		}
		if n%2 == 0 {
			q := n / 2
			for i := n; i > 0; i-- {
				if i > q {
					fmt.Println(-ARR[i])
				} else {
					fmt.Println(ARR[i])

				}
			}
		} else {
			q := (n + 1) / 2
			first := ARR[1]
			Midd := ARR[q]
			Last := ARR[n]
			var F, M, L int

			if first != Midd && Midd != Last && Last != Midd {
				if first-Midd <= 10000 && first-Midd >= -10000 {
					F = -Last
					M = Last
					L = first - Midd
				} else {
					if Last-first <= 10000 && Last-first >= -10000 {
						F = -Midd
						M = first - Last
						L = Midd
					} else {
						if Last-Midd <= 10000 && Last-Midd >= -10000 {
							F = Last - Midd
							M = first
							L = -first
						}
					}
				}

			} else {
				if first == Midd {
					if Last != 1 && Last != -1 && Last != -2 {
						F = -(Last / 2)
						M = -(Last + 1) / 2
						L = first
					} else {
						F = -Last
						M = -Last
						L = first
					}
				} else {
					if first == Last {
						if Midd != 1 && Midd != -1 && Midd != -2 {
							F = -(Midd / 2)
							L = -(Midd + 1) / 2
							M = first
						} else {
							F = -Midd
							M = -Midd
							L = first
						}
					} else {
						if first != 1 && first != -1 && first != -2 {
							M = -first / 2
							L = -(first + 1) / 2
							F = Midd
						} else {
							F = -first
							M = -first
							L = Last
						}
					}
				}
			}
			fmt.Println(F)
			for i := n - 1; i > q; i-- {
				fmt.Println(-ARR[i])
			}

			fmt.Println(M)
			for i := q - 1; i > 1; i-- {
				fmt.Println(ARR[i])
			}
			fmt.Println(L)
		}

	}

}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

var t int

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

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		Pos := 0
		Neg := 0
		ARR := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(input, &ARR[i])
			if ARR[i] < 0 {
				Neg++
			} else {
				Pos++
			}

		}
		if n%2 == 0 {
			q := n / 2
			for i := n; i > 0; i-- {
				if i > q {
					fmt.Println(-ARR[i])
				} else {
					fmt.Println(ARR[i])

				}
			}
		} else {
			q := (n + 1) / 2
			first := ARR[1]
			Midd := ARR[q]
			Last := ARR[n]
			var F, M, L int

			if first != Midd && Midd != Last && Last != Midd {
				if first-Midd <= 10000 && first-Midd >= -10000 {
					F = -Last
					M = Last
					L = first - Midd
				} else {
					if Last-first <= 10000 && Last-first >= -10000 {
						F = -Midd
						M = first - Last
						L = Midd
					} else {
						if Last-Midd <= 10000 && Last-Midd >= -10000 {
							F = Last - Midd
							M = first
							L = -first
						}
					}
				}

			} else {
				if first == Midd {
					if Last != 1 && Last != -1 {
						F = -(Last / 2)
						M = -(Last + 1) / 2
						L = first
					} else {
						F = -Last
						M = -Last
						L = first
					}
				} else {
					if first == Last {
						if Midd != 1 && Midd != -1 {
							F = -(Midd / 2)
							L = -(Midd + 1) / 2
							M = first
						} else {
							F = -Midd
							M = -Midd
							L = first
						}
					} else {
						if first != 1 && first != -1 {
							M = -first / 2
							L = -(first + 1) / 2
							F = Midd
						} else {
							F = -first
							M = -first
							L = Last
						}
					}
				}
			}
			fmt.Println(F)
			for i := n - 1; i > q; i-- {
				fmt.Println(-ARR[i])
			}

			fmt.Println(M)
			for i := q - 1; i > 1; i-- {
				fmt.Println(ARR[i])
			}
			fmt.Println(L)
		}

	}

}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

var t int

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

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		Pos := 0
		Neg := 0
		ARR := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(input, &ARR[i])
			if ARR[i] < 0 {
				Neg++
			} else {
				Pos++
			}

		}
		if n%2 == 0 {
			q := n / 2
			for i := n; i > 0; i-- {
				if i > q {
					fmt.Println(-ARR[i])
				} else {
					fmt.Println(ARR[i])

				}
			}
		} else {
			q := (n + 1) / 2
			first := ARR[1]
			Midd := ARR[q]
			Last := ARR[n]
			var F, M, L int

			if first != Midd && Midd != Last && Last != Midd {
				if first-Midd <= 10000 && first-Midd >= -10000 {
					F = -Last
					M = Last
					L = first - Midd
				} else {
					if Last-first <= 10000 && Last-first >= -10000 {
						F = -Midd
						M = first - Last
						L = Midd
					} else {
						if Last-Midd <= 10000 && Last-Midd >= -10000 {
							F = Last - Midd
							M = first
							L = -first
						}
					}
				}

			} else {
				if first == Midd {
					F = -(Last / 2)
					M = -(Last + 1) / 2
					L = first
				} else {
					if first == Last {
						F = -(Midd / 2)
						L = -(Midd + 1) / 2
						M = first
					} else {
						M = -first / 2
						L = -(first + 1) / 2
						F = Midd
					}
				}
			}
			fmt.Println(F)
			for i := n - 1; i > q; i-- {
				fmt.Println(-ARR[i])
			}

			fmt.Println(M)
			for i := q - 1; i > 1; i-- {
				fmt.Println(ARR[i])
			}
			fmt.Println(L)
		}

	}

}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

var t int

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

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		Pos := 0
		Neg := 0
		ARR := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Fscan(input, &ARR[i])
			if ARR[i] < 0 {
				Neg++
			} else {
				Pos++
			}

		}
		if n%2 == 0 {
			q := n / 2
			for i := n; i > 0; i-- {
				if i > q {
					fmt.Println(-ARR[i])
				} else {
					fmt.Println(ARR[i])

				}
			}
		} else {
			q := (n + 1) / 2
			first := ARR[1]
			Midd := ARR[q]
			Last := ARR[n]

			var F, M, L int
			if first-Midd <= 10000 && first-Midd >= -10000 {
				F = -Last
				M = Last
				L = first - Midd
			} else {
				if Last-first <= 10000 && Last-first >= -10000 {
					F = -Midd
					M = first - Last
					L = Midd
				} else {
					if Last-Midd <= 10000 && Last-Midd >= -10000 {
						F = Last - Midd
						M = first
						L = -first
					}
				}
			}

			fmt.Println(F)
			for i := n - 1; i > q; i-- {
				fmt.Println(-ARR[i])
			}

			fmt.Println(M)
			for i := q - 1; i > 1; i-- {
				fmt.Println(ARR[i])
			}
			fmt.Println(L)
		}

	}

}

package main

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

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

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

	var T, n int
	for fmt.Fscan(r, &T); T > 0; T-- {
		fmt.Fscan(r, &n)
		arr := make([]int64, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &arr[i])
		}

		res := make([]int64, n)
		if n%2 == 0 {
			for i := 0; i < n; i += 2 {
				if (arr[i] > 0 && arr[i+1] > 0) || (arr[i] < 0 && arr[i+1] < 0) {
					res[i] = arr[i+1]
					res[i+1] = -arr[i]
				} else {
					res[i] = -arr[i+1]
					res[i+1] = arr[i]
				}
			}
		} else {
			for i := 0; i < n-3; i += 2 {
				if (arr[i] > 0 && arr[i+1] > 0) || (arr[i] < 0 && arr[i+1] < 0) {
					res[i] = arr[i+1]
					res[i+1] = -arr[i]
				} else {
					res[i] = -arr[i+1]
					res[i+1] = arr[i]
				}
			}

			a, b := arr[n-3], arr[n-2]+arr[n-1]
			if (a > 0 && b > 0) || (a < 0 && b < 0) {
				res[n-3] = b
				res[n-2] = -a
				res[n-1] = -a
			} else {
				res[n-3] = -b
				res[n-2] = a
				res[n-1] = a
			}
		}
		for _, v := range res {
			fmt.Fprint(w, v, " ")
		}
		fmt.Fprintln(w)
	}
}

package main

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

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

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

	var T, n int
	for fmt.Fscan(r, &T); T > 0; T-- {
		fmt.Fscan(r, &n)
		arr := make([]int64, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &arr[i])
		}

		res := make([]int64, n)
		if n%2 == 0 {
			for i := 0; i < n; i += 2 {
				if (arr[i] > 0 && arr[i+1] > 0) || (arr[i] < 0 && arr[i+1] < 0) {
					res[i] = arr[i+1]
					res[i+1] = -arr[i]
				} else {
					res[i] = arr[i+1]
					res[i+1] = arr[i]
				}
			}
		} else {
			for i := 0; i < n-3; i += 2 {
				if (arr[i] > 0 && arr[i+1] > 0) || (arr[i] < 0 && arr[i+1] < 0) {
					res[i] = arr[i+1]
					res[i+1] = -arr[i]
				} else {
					res[i] = arr[i+1]
					res[i+1] = arr[i]
				}
			}

			a, b := arr[n-3], arr[n-2]+arr[n-1]
			if (a > 0 && b > 0) || (a < 0 && b < 0) {
				res[n-3] = b
				res[n-2] = -a
				res[n-1] = -a
			} else {
				res[n-3] = -b
				res[n-2] = a
				res[n-1] = a
			}
		}
		for _, v := range res {
			fmt.Fprint(w, v, " ")
		}
		fmt.Fprintln(w)
	}
}

package main

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

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

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

	var T, n int
	for fmt.Fscan(r, &T); T > 0; T-- {
		fmt.Fscan(r, &n)
		arr := make([]int64, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &arr[i])
		}

		res := make([]int64, n)
		if n%2 == 0 {
			for i := 0; i < n; i += 2 {
				if arr[i] > 0 && arr[i+1] > 0 || arr[i] < 0 && arr[i+1] < 0 {
					res[i] = arr[i+1]
					res[i+1] = -arr[i]
				} else {
					res[i] = arr[i+1]
					res[i+1] = arr[i]
				}
			}
		} else {
			for i := 0; i < n-3; i += 2 {
				if arr[i] > 0 && arr[i+1] > 0 || arr[i] < 0 && arr[i+1] < 0 {
					res[i] = arr[i+1]
					res[i+1] = -arr[i]
				} else {
					res[i] = arr[i+1]
					res[i+1] = arr[i]
				}
			}

			a, b := arr[n-3], arr[n-2]+arr[n-1]
			if a > 0 && b > 0 || a < 0 && b < 0 {
				res[n-3] = b
				res[n-2] = -a
				res[n-1] = -a
			} else {
				res[n-3] = b
				res[n-2] = a
				res[n-1] = a
			}
		}
		for _, v := range res {
			fmt.Fprint(w, v, " ")
		}
		fmt.Fprintln(w)
	}
}

package main

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

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

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

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

func main() {
	var T int
	scanf("%d", &T)
	for t := 0; t < T; t++ {
		var n int
		scanf("\n%d\n", &n)
		arr := make([]int,n)
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}
		brr := make([]int, n)
		round := n / 2 * 2
		for i := 0; i < round; i += 2 {
			lcm := arr[i] * arr[i + 1] / gcd(arr[i], arr[i + 1])
			brr[i] -= lcm / arr[i]
			brr[i + 1] += lcm / arr[i + 1]
		}
		if n % 2 == 1 {
			lcm := arr[n - 1] * arr[n - 2] / gcd(arr[n - 1], arr[n - 2])
			if brr[n - 1] + lcm / arr[n - 1] != 0 {
				brr[n - 1] += lcm / arr[n - 1]
				brr[n - 2] -= lcm / arr[n - 2]
			} else {
				brr[n - 1] -= lcm / arr[n - 1]
				brr[n - 2] += lcm / arr[n - 2]
			}
		}
		for i := 0; i < n; i++ {
			fmt.Printf("%d ", brr[i])
		}
		fmt.Printf("\n")
	}
}

package main

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

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

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

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

func main() {
	var T int
	scanf("%d", &T)
	for t := 0; t < T; t++ {
		var n int
		scanf("\n%d\n", &n)
		arr := make([]int,n)
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}
		brr := make([]int, n)
		round := n / 2 * 2
		for i := 0; i < round; i += 2 {
			lcm := arr[i] * arr[i + 1] / gcd(arr[i], arr[i + 1])
			brr[i] -= lcm / arr[i]
			brr[i + 1] += lcm / arr[i + 1]
		}
		if n % 2 == 1 {
			lcm := arr[n - 1] * arr[n - 2] / gcd(arr[n - 1], arr[n - 2])
			if brr[n - 1] > 0 {
				brr[n - 1] += lcm / arr[n - 1]
				brr[n - 2] -= lcm / arr[n - 2]
			} else {
				brr[n - 1] -= lcm / arr[n - 1]
				brr[n - 2] += lcm / arr[n - 2]
			}
		}
		for i := 0; i < n; i++ {
			fmt.Printf("%d ", brr[i])
		}
		fmt.Printf("\n")
	}
}

package main

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

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

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

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

func main() {
	var T int
	scanf("%d", &T)
	for t := 0; t < T; t++ {
		var n int
		scanf("\n%d\n", &n)
		arr := make([]int,n)
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}
		brr := make([]int, n)
		round := n / 2 * 2
		for i := 0; i < round; i += 2 {
			lcm := arr[i] * arr[i + 1] / gcd(arr[i], arr[i + 1])
			brr[i] -= lcm / arr[i]
			brr[i + 1] += lcm / arr[i + 1]
		}
		if n % 2 == 1 {
			lcm := arr[n - 1] * arr[n - 2] / gcd(arr[n - 1], arr[n - 2])
			brr[n - 1] += lcm / arr[n - 1]
			brr[n - 2] -= lcm / arr[n - 2]
		}
		for i := 0; i < n; i++ {
			fmt.Printf("%d ", brr[i])
		}
		fmt.Printf("\n")
	}
}

package main

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

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

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

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

func main() {
	var T int
	scanf("%d", &T)
	for t := 0; t < T; t++ {
		var n int
		scanf("\n%d\n", &n)
		arr := make([]int,n)
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}
		brr := make([]int, n)
		round := n / 2 * 2
		for i := 0; i < round; i += 2 {
			lcm := arr[i] * arr[i + 1] / gcd(arr[i], arr[i + 1])
			brr[i] -= lcm / arr[i]
			brr[i + 1] += lcm / arr[i + 1]
		}
		if n % 2 == 1 {
			lcm := arr[n - 1] * arr[n - 2] / gcd(arr[n - 1], arr[n - 2])
			brr[n - 1] -= lcm / arr[n - 1]
			brr[n - 2] += lcm / arr[n - 2]
		}
		for i := 0; i < n; i++ {
			fmt.Printf("%d ", brr[i])
		}
		fmt.Printf("\n")
	}
}

package main

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

var n int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		a = make([]int, n)

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

		solve()

	}
}

func solve() {
	//5 -2 10 -9 4
	//5* a1 + (-2) * a2 + 10 * a3 + (-9)*a4 + 4 * a5 == 0

	if n % 2 == 0 {
		for i := 0; i < n; i+=2 {
			g := GCD(a[i + 1], a[i])

			a1 := a[i + 1]/g
			a0 := a[i]/g

			fmt.Print(-a1)
			fmt.Print(" ")
			fmt.Print(a0)
			fmt.Print(" ")
		}
		fmt.Println()
	 } else {
		for i := 0; i < n - 3; i+=2 {
			g := GCD(a[i + 1], a[i])

			a1 := a[i + 1]/g
			a0 := a[i]/g

			fmt.Print(-a1)
			fmt.Print(" ")
			fmt.Print(a0)
			fmt.Print(" ")
		}

		d := a[n - 1] + a[n - 2]

		g := GCD(d, a[n - 3])

		a1 := d/g
		a0 := a[n - 3]/g

		fmt.Print(-a1)
		fmt.Print(" ")
		fmt.Print(a0)
		fmt.Print(" ")
		fmt.Print(a0)
		fmt.Print(" ")
		fmt.Println()
	}

}

// greatest common divisor (GCD) via Euclidean algorithm
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

package main

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

var n int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		a = make([]int, n)

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

		solve()

	}
}

func solve() {
	//5 -2 10 -9 4
	//5* a1 + (-2) * a2 + 10 * a3 + (-9)*a4 + 4 * a5 == 0

	if n % 2 == 0 {
		for i := 0; i < n; i+=2 {
			fmt.Print(-a[i + 1])
			fmt.Print(" ")
			fmt.Print(a[i])
			fmt.Print(" ")
		}
		fmt.Println()
	 } else {
		for i := 0; i < n - 3; i+=2 {
			fmt.Print(-a[i + 1])
			fmt.Print(" ")
			fmt.Print(a[i])
			fmt.Print(" ")
		}

		d := a[n - 1] + a[n - 2]

		fmt.Print(-d)
		fmt.Print(" ")
		fmt.Print(a[n - 3])
		fmt.Print(" ")
		fmt.Print(a[n - 3])
		fmt.Print(" ")
		fmt.Println()
	}

}

package main

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

func gcd(x, y int)int{
	for y>0{
		t := x%y
		x = y
		y = t
	}
	return x
}
func lcm(x, y int)int{
	return x*y/gcd(x,y)
}
func abs(x int)int{
	if x<0{
		return -x
	}
	return x
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n int
		fmt.Fscan(in,&n)
		a := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		ans := []int{}
		for i:=1;i<=n;i+=2{
			if n%2==1&&i==n{
				break
			}
			var x, y int
			if n%2==1&&i==n-2{
				if a[i]+a[i+2]!=0{
					y = a[i]+a[i+2]
					x = a[i+1]
					k := lcm(abs(x),abs(y))
					dx := k/abs(x)
					dy := k/abs(y)
					if x>0&&y>0{
						ans = append(ans,dy,-dx,dy)
					}
					if (x>0&&y<0)||(x<0&&y>0){
						ans = append(ans,dy,-dx,dy)
					}
					if x<0&&y<0{
						ans = append(ans,dy,-dx,dy)
					}
				}else if a[i]+a[i+1]!=0{
					y = a[i]+a[i+1]
					x = a[i+2]
					k := lcm(abs(x),abs(y))
					dx := k/abs(x)
					dy := k/abs(y)
					if x>0&&y>0{
						ans = append(ans,dy,dy,-dx)
					}
					if (x>0&&y<0)||(x<0&&y>0){
						ans = append(ans,dy,dy,-dx)
					}
					if x<0&&y<0{
						ans = append(ans,dy,dy,-dx)
					}
				}else{
					y=a[i+1]+a[i+2]
					x=a[i]
					k := lcm(abs(x),abs(y))
					dx := k/abs(x)
					dy := k/abs(y)
					if x>0&&y>0{
						ans = append(ans,-dx,dy,dy)
					}
					if (x>0&&y<0)||(x<0&&y>0){
						ans = append(ans,dx,dy,dy)
					}
					if x<0&&y<0{
						ans = append(ans,-dx,dy,dy)
					}
				}
				continue
			}else {
				x = a[i]
				y = a[i+1]
			}
			k := lcm(abs(x),abs(y))
			dx := k/abs(x)
			dy := k/abs(y)
			if x>0&&y>0{
				ans = append(ans,-dx,dy)
			}
			if (x>0&&y<0)||(x<0&&y>0){
				ans = append(ans,dx,dy)
			}
			if x<0&&y<0{
				ans = append(ans,-dx,dy)
			}
			if n%2==1&&i==n-2{
				ans = append(ans,dy)
			}
		}
		for i:=0;i<len(ans);i++{
			fmt.Fprintf(out,"%d ",ans[i])
		}
		fmt.Fprintln(out)
	}
}