package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)

		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(n int, A []int) int {
	cnt := make([]int, n+1)
	var mx int
	for i := 0; i < n; i++ {
		cnt[A[i]]++
		if cnt[A[i]] > mx {
			mx = cnt[A[i]]
		}
	}

	var y, k int

	for i := 1; i <= n; i++ {
		if cnt[i] == mx {
			k++
		} else {
			y += cnt[i]
		}
	}

	return y/(mx-1) + k - 1
}

const N = 100010

var B [N]int

func solve1(n int, A []int) int {

	check := func(dist int) bool {
		if dist == 1 {
			return true
		}
		cnt := make(map[int]int)
		for i := 0; i < n; i++ {
			cnt[A[i]]++
		}

		ps := make(Pairs, 0, len(cnt))

		for k, v := range cnt {
			p := Pair{v, k, len(ps) - 1}
			heap.Push(&ps, &p)
		}

		for i := 0; i < n; i++ {
			if i >= dist && cnt[B[i-dist]] > 0 {
				p := Pair{cnt[B[i-dist]], B[i-dist], len(ps) - 1}
				heap.Push(&ps, &p)
			}
			if len(ps) == 0 {
				return false
			}
			cur := heap.Pop(&ps).(*Pair)
			B[i] = cur.second
			cnt[cur.second]--
		}

		return true
	}

	var left = 2
	var right = n
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 2
}

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

type Pair struct {
	first, second int
	index         int
}

type Pairs []*Pair

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

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

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

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

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

package main

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

type cce struct {
	v, c int
}

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

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

	for t := in(); t > 0; t-- {
		n := in()

		vc := make(map[int]int)

		for i := 0; i < n; i++ {
			vc[in()]++
		}

		//fmt.Println(vc)
		cc := make(map[int]int)

		for _, c := range vc {
			cc[c]++
		}

		//fmt.Println(cc)

		ccl := make([]cce, len(cc))

		c := 0
		for k, v := range cc {
			ccl[c].v = k
			ccl[c].c = v
			c++
		}

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

		//fmt.Println(ccl)

		val := 0

		for i := 1; i < len(ccl); i++ {
			val += (ccl[i].c * ccl[i].v)
		}

		val /= (ccl[0].v - 1)

		val += (ccl[0].c - 1)

		fmt.Println(val)
	}
}

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		n:=0
		Fscan(in, &n)
		freq:=make(map[int]int)
		for i:=0;i<n;i++{
			var k int
			Fscan(in,&k)
			freq[k]++
		}
		// Fprintln(out,freq)
		bs:=func(mid int) bool{
			q,r:=n/mid,n%mid
			for _,v:=range(freq){
				// Fprintln(out,x,v)
				if v>q+1{
					return false
				}
				if v==q+1{
					r--
				}
			}
			return r>=0
		}

		left,right:=0,n+1
		for right-left>1{
			mid:=(left+right)/2
			// Fprintln(out,mid,bs(mid+1))
			if bs(mid+1){
				left=mid
			} else {
				right=mid
			}
		}
		Fprintln(out,left)
	}
}

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

/*
URL:
https://codeforces.com/contest/1393/problem/C
*/

package main

import (
	"bufio"
	"container/heap"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

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

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

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

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

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

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

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

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

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

var (
	t int

	n    int
	A    []int
	cnts []int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		A = ReadIntSlice(n)
		cnts = make([]int, n+5)

		solve()
	}
}

func solve() {
	for _, a := range A {
		cnts[a]++
	}

	ok := BinarySearch(0, n, func(x int) bool {
		B := []*Element{}

		pq := NewElementPQ()
		for i := 1; i <= n; i++ {
			if cnts[i] >= 1 {
				pq.push(&Element{val: i, num: cnts[i]})
			}
		}

		C := []int{}
		for pq.Len() > 0 {
			resi := x + 1

			for resi > 0 {
				if pq.Len() == 0 {
					// return false
					break
				}

				pop := pq.pop()
				C = append(C, pop.val)
				pop.num--
				if pop.num > 0 {
					B = append(B, pop)
				}
				resi--
			}

			for _, e := range B {
				pq.push(e)
			}
			B = []*Element{}
		}

		bef := make([]int, n+5)
		for i := 1; i <= n; i++ {
			bef[i] = -1
		}

		// PrintfDebug("C: %v, x: %d\n", C, x)
		for i := 0; i < len(C); i++ {
			if bef[C[i]] == -1 {
				bef[C[i]] = i
				continue
			}

			dist := i - bef[C[i]] - 1
			// PrintfDebug("dist: %d\n", dist)
			if dist < x {
				return false
			}
			bef[C[i]] = i
		}
		// PrintfDebug("bef: %v\n", bef)
		// PrintfDebug("OK\n")

		return true
	})

	fmt.Println(ok)
}

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

type Element struct {
	pri      int
	val, num int
}
type ElementPQ []*Element

// Interfaces
func NewElementPQ() *ElementPQ {
	temp := make(ElementPQ, 0)
	pq := &temp
	heap.Init(pq)

	return pq
}
func (pq *ElementPQ) push(target *Element) {
	heap.Push(pq, target)
}
func (pq *ElementPQ) pop() *Element {
	return heap.Pop(pq).(*Element)
}

func (pq ElementPQ) Len() int { return len(pq) }
func (pq ElementPQ) Less(i, j int) bool {
	if pq[i].num > pq[j].num {
		return true
	} else if pq[i].num < pq[j].num {
		return false
	} else {
		return pq[i].val < pq[j].val
	}
} // <: ASC, >: DESC
func (pq ElementPQ) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}
func (pq *ElementPQ) Push(x interface{}) {
	item := x.(*Element)
	*pq = append(*pq, item)
}
func (pq *ElementPQ) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

// func solve() {
// 	for _, a := range A {
// 		cnts[a]++
// 	}
// 	PrintfDebug("cnts: %v\n", cnts)

// 	C := []int{}
// 	for i := 1; i <= n; i++ {
// 		C = append(C, cnts[i])
// 	}
// 	sort.Sort(sort.Reverse(sort.IntSlice(C)))

// 	if C[0] != C[1] {
// 		// 個数について単独首位がある
// 		cnt := C[0]
// 		ans := (n - cnt) / (cnt - 1)
// 		fmt.Println(ans)
// 		return
// 	}

// 	comp, cc := RunLengthEncoding(C)
// 	fv, sv := comp[0], comp[1]
// 	fk, sk := cc[0], cc[1]
// 	PrintfDebug("fv: %d, fk: %d, sv: %d, sk: %d\n", fv, fk, sv, sk)

// 	ans := fk - 1
// 	if fv-sv >= 2 {
// 		fmt.Println(ans)
// 	} else {
// 		fmt.Println(ans + sk)
// 	}
// }

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)

		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
}

const N = 100010

var B [N]int

func solve(n int, A []int) int {

	check := func(dist int) bool {
		if dist == 1 {
			return true
		}
		cnt := make(map[int]int)
		for i := 0; i < n; i++ {
			cnt[A[i]]++
		}

		ps := make(Pairs, 0, len(cnt))

		for k, v := range cnt {
			p := Pair{v, k, len(ps) - 1}
			heap.Push(&ps, &p)
		}

		for i := 0; i < n; i++ {
			if i >= dist && cnt[B[i-dist]] > 0 {
				p := Pair{cnt[B[i-dist]], B[i-dist], len(ps) - 1}
				heap.Push(&ps, &p)
			}
			if len(ps) == 0 {
				return false
			}
			cur := heap.Pop(&ps).(*Pair)
			B[i] = cur.second
			cnt[cur.second]--
		}

		return true
	}

	var left = 2
	var right = n
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 2
}

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

type Pair struct {
	first, second int
	index         int
}

type Pairs []*Pair

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

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

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

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

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

package main

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

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

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

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

	t := readInt()
	for ; t > 0; t-- {
		n := readInt()
		counts := make([]int, n+1)
		candies := readInts()
		for _, c := range candies {
			counts[c]++
		}
		sort.Ints(counts)

		max := counts[n]
		var i int64
		for i = n-1; i >= 0; i-- {
			if counts[i] != max {
				break
			}
		}
		max_count := n-i
		var left int64
		for ; i >= 0; i-- {
			left += int64(counts[i])
		}
		ans := left/(int64(max)-1) + max_count - 1
		fmt.Fprintln(writer, ans)
	}

	writer.Flush()
}

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

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

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

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

package main

import (
    "fmt"
)

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

func main() {
    var t int
    fmt.Scan(&t)
    for t > 0 {
        var n int
        fmt.Scan(&n)
        f := make([]int, n)
        for i := 0; i < n; i++ {
            fmt.Scan(&f[i])
        }

        cnt := make([]int, n + 1)
        for i := 0; i < n; i++ {
            cnt[f[i]]++
        }

        mx, total := 0, 0
        for i := 1; i <= n; i++ {
            if cnt[i] > mx {
                mx = cnt[i]
                total = 1
            } else if cnt[i] == mx {
                total++
            }
        }

        fmt.Println((n - (total - 1) - mx) / (mx - 1))

        t--
    }
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		counts := map[int64]int64{}
		n := sint64()
		for i := int64(0); i < n; i++ {
			counts[sint64()]++
		}
		printf("%d\n", sol(n, counts))
	}
}

func sol(n int64, counts map[int64]int64) int64 {
	maxCount := int64(0)
	maxCountFreq := int64(0)
	for _, c := range counts {
		if c > maxCount {
			maxCount = c
			maxCountFreq = 1
		} else if c == maxCount {
			maxCountFreq++
		}
	}
	// printf("maxCount maxCountFreq %d %d\n", maxCount, maxCountFreq)
	rem := n - (maxCount * maxCountFreq)
	ngaps := maxCount - 1
	filledGaps := int64(0)
	if ngaps > 0 {
		filledGaps = rem / ngaps
	}
	return maxCountFreq - 1 + filledGaps
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)

		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
}

const N = 100010

var B [N]int

func solve(n int, A []int) int {
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		cnt[A[i]]++

	}
	ps := make([]Pair, 0, len(cnt))
	for k, v := range cnt {
		ps = append(ps, Pair{v, k})
	}

	sort.Sort(Pairs(ps))

	check := func(dist int) bool {
		if dist == 1 {
			return true
		}

		var j int
		var offset int

		for i := 0; i < len(ps); i++ {
			cur := ps[i]
			a := cur.first
			jj := j
			for a > 0 {
				if j != jj && abs(jj-j) < dist {
					return false
				}

				a--

				if j+dist < n {
					j += dist
				} else {
					offset++
					j = offset
				}
			}
		}

		return true
	}

	var left = 2
	var right = n
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 2
}

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

type Pair struct {
	first, second int
}

type Pairs []Pair

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

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

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

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)

		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
}

const N = 100010

var B [N]int

func solve(n int, A []int) int {
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		cnt[A[i]]++

	}
	ps := make([]Pair, 0, len(cnt))
	for k, v := range cnt {
		ps = append(ps, Pair{v, k})
	}

	sort.Sort(Pairs(ps))

	check := func(dist int) bool {
		if dist == 0 {
			return true
		}
		var offset int
		var j int
		var ok = true
		for i := 0; i < len(ps) && ok; i++ {
			cur := ps[i]
			a, b := cur.first, cur.second
			for a > 0 {
				for a > 0 && j < n {
					a--
					B[j] = b
					j += dist
				}
				offset++
				j = offset
				for j < n && B[j] > 0 {
					j++
				}
			}

		}
		pos := make(map[int]int)
		if ok {
			for i := 0; i < n && ok; i++ {
				if B[i] == 0 {
					ok = false
				}
				if j, found := pos[B[i]]; found && i-j < dist {
					ok = false
				}
				pos[B[i]] = i
			}
		}
		for i := 0; i < n; i++ {
			B[i] = 0
		}
		return ok
	}

	var left int
	var right = n
	for left < right {
		mid := (left + right) / 2
		if check(mid) {
			left = mid + 1
		} else {
			right = mid
		}
	}
	return right - 2
}

type Pair struct {
	first, second int
}

type Pairs []Pair

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

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

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

package main

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

type cce struct {
	v, c int
}

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

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

	for t := in(); t > 0; t-- {
		n := in()

		vc := make(map[int]int)

		for i := 0; i < n; i++ {
			vc[in()]++
		}

		//fmt.Println(vc)
		cc := make(map[int]int)

		for _, c := range vc {
			cc[c]++
		}

		//fmt.Println(cc)

		ccl := make([]cce, len(cc))

		c := 0
		for k, v := range cc {
			ccl[c].v = k
			ccl[c].c = v
			c++
		}

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

		//fmt.Println(ccl)

		val := ccl[0].c - 1

		for i := 1; i < len(ccl); i++ {
			val += ccl[i].c * ccl[i].v / (ccl[0].v - 1)
		}

		fmt.Println(val)
	}
}

package main

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

type cce struct {
	v, c int
}

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

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

	for t := in(); t > 0; t-- {
		n := in()

		vc := make(map[int]int)

		for i := 0; i < n; i++ {
			vc[in()]++
		}

		//fmt.Println(vc)
		cc := make(map[int]int)

		for _, c := range vc {
			cc[c]++
		}

		//fmt.Println(cc)

		ccl := make([]cce, len(cc))

		c := 0
		for k, v := range cc {
			ccl[c].v = k
			ccl[c].c = v
			c++
		}

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

		//fmt.Println(ccl)

		val := ccl[0].c - 1

		for i := 1; i < len(ccl); i++ {
			val += (ccl[i].c * ccl[i].v) / (ccl[0].v - 1)
		}

		fmt.Println(val)
	}
}

package main

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

type cce struct {
	v, c int
}

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

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

	for t := in(); t > 0; t-- {
		n := in()

		vc := make(map[int]int)

		for i := 0; i < n; i++ {
			vc[in()]++
		}

		// fmt.Println(vc)
		cc := make(map[int]int)

		for _, c := range vc {
			cc[c]++
		}

		// fmt.Println(cc)

		ccl := make([]cce, len(cc))

		c := 0
		for k, v := range cc {
			ccl[c].v = k
			ccl[c].c = v
			c++
		}

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

		val := ccl[0].c - 1

		for i := 1; i < len(ccl); i++ {
			val += ccl[i].c / (ccl[0].v - ccl[i].v)
		}

		fmt.Println(val)
	}
}

/*
URL:
https://codeforces.com/contest/1393/problem/C
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n    int
	A    []int
	cnts []int
)

func main() {
	t = ReadInt()
	for tc := 0; tc < t; tc++ {
		n = ReadInt()
		A = ReadIntSlice(n)
		cnts = make([]int, n+5)

		solve()
	}
}

func solve() {
	for _, a := range A {
		cnts[a]++
	}
	PrintfDebug("cnts: %v\n", cnts)

	C := []int{}
	for i := 1; i <= n; i++ {
		C = append(C, cnts[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(C)))

	if C[0] != C[1] {
		// 個数について単独首位がある
		cnt := C[0]
		ans := (n - cnt) / (cnt - 1)
		fmt.Println(ans)
		return
	}

	comp, cc := RunLengthEncoding(C)
	fv, sv := comp[0], comp[1]
	fk, sk := cc[0], cc[1]
	PrintfDebug("fv: %d, fk: %d, sv: %d, sk: %d\n", fv, fk, sv, sk)

	ans := fk - 1
	if fv-sv >= 2 {
		fmt.Println(ans)
	} else {
		fmt.Println(ans + sk)
	}
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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


package main

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

var in = bufio.NewReader(os.Stdin)

func solve() {
	var n, q, k int64
	_, _ = fmt.Fscan(in, &n, &q, &k)
	arr := make([]int64, n)
	for i := 0; i < len(arr); i++ {
		fmt.Fscan(in, &arr[i])
	}
	p := make([]int64, n)
	if len(arr) == 1 {
		p[0] = k - 1
	} else {
		p[0] = arr[1] - 1 - 1
		for i := 1; i < len(arr)-1; i++ {
			t := arr[i+1] - arr[i-1] - 2
			p[i] = t
		}
		p[len(p)-1] = k - arr[len(arr)-1]
	}
	s := make([]int64, n)
	s[0] = p[0]
	t := s[0]
	for i := 1; i < len(arr); i++ {
		t += p[i]
		s[i] = t
	}
	for i := 0; i < int(q); i++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		if x == y {
			fmt.Println(k - 1)
		} else {
			var count int64
			t1 := arr[x] - 1 - 1
			t2 := k - arr[y-2] - 1
			t3 := s[y-2] - s[x-1]
			count += t1
			count += t2
			count += t3
			fmt.Println(count)

		}
	}

}

func main() {
	solve()
}

package main

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

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

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

//https://codeforces.com/problemset/problem/1485/B

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	solve()
}

func solve() {
	n, q, k := nextNum(), nextNum(), nextNum()
	a := make([]int, n)
	// dp := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextNum()
		// if i > 0 {
		// 	dp[i] = dp[i-1] + a[i] - a[i-1] - 1
		// }
	}
	for i := 0; i < q; i++ {
		l, r := nextNum()-1, nextNum()-1
		// println(a[l] - 1 + k - a[r] + (dp[r]-dp[l])*2)
		println(a[l] - 1 + k - a[r] + (a[r]-a[l]-(r-l))*2)
	}
}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

package main

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

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

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

//https://codeforces.com/problemset/problem/1485/B

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	solve()
}

func solve() {
	n, q, k := nextNum(), nextNum(), nextNum()
	a := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextNum()
		if i > 0 {
			dp[i] = dp[i-1] + a[i] - a[i-1] - 1
		}
	}
	for i := 0; i < q; i++ {
		l, r := nextNum()-1, nextNum()-1
		println(a[l] - 1 + k - a[r] + (dp[r]-dp[l])*2)
	}
}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}

package main

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

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

	var buf bytes.Buffer

	n, q, k := readThreeNums(reader)
	A := readNNums(reader, n)
	Q := make([][]int, q)
	for i := 0; i < q; i++ {
		Q[i] = readNNums(reader, 2)
	}
	res := solve(n, q, k, A, Q)

	for i := 0; i < q; i++ {
		buf.WriteString(fmt.Sprintf("%d\n", res[i]))
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, q int, k int, A []int, Q [][]int) []int {
	ans := make([]int, q)

	for i := 0; i < q; i++ {
		l, r := Q[i][0], Q[i][1]
		l--
		r--
		if l == r {
			ans[i] = k - 1
			continue
		}
		//  𝑘+(𝑎𝑟−𝑎𝑙+1)−2(𝑟−𝑙+1)
		ans[i] = k + A[r] - A[l] + 1 - 2*(r-l+1)
	}

	return ans
}

package main

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

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

	var (
		n, q int
		k    int64
	)
	fmt.Fscanln(input, &n, &q, &k)
	data := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &data[i])
	}
	fmt.Fscanf(input, "\n")
	sum := make([]int64, n)
	for i := 2; i < n; i++ {
		sum[i] = data[i+1] - data[i-1] - 2
		sum[i] += sum[i-1]
	}
	for ; q > 0; q-- {
		var l, r int
		fmt.Fscanln(input, &l, &r)
		if l == r {
			fmt.Println(k - 1)
			continue
		}
		res := sum[r-1] - sum[l+1-1]
		res += data[l+1] - 2
		res += k - data[r-1] - 1
		fmt.Println(res)
	}
}

package main

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

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

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

}

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

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	var n int
	var q int
	var k int
	fmt.Fscan(input, &n)
	fmt.Fscan(input, &q)
	fmt.Fscan(input, &k)

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

	for o := 0; o < q; o++ {
		var l int
		var r int
		fmt.Fscan(input, &l)
		fmt.Fscan(input, &r)
		var ans int64
		ans = ARRAY[r] - ARRAY[l] + int64(k) - int64(2)*int64(r-l) - int64(1)
		fmt.Println(ans)
	}

}

package main

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

func main() {
	var tcs int = 1
	in := bufio.NewReader(os.Stdin)

	for tc := 0; tc < tcs; tc++ {
		var n, q, k int64
		_, _ = fmt.Fscan(in, &n, &q, &k)
		a := make([]int64, n+2)
		s := make([]int64, n+2)

		for i := int64(1); i < n+1; i++ {
			_, _ = fmt.Fscan(in, &a[i])
		}
		a[n+1] = k
		for i := int64(1); i < n+1; i++ {
			s[i] = s[i-1] + a[i+1] - a[i-1] - 2
		}

		for i := int64(0); i < q; i++ {
			var l, r int
			_, _ = fmt.Fscan(in, &l, &r)
			var ans int64
			if l < r {
				ans = s[r-1] - s[l] + (a[l+1] - 1) + (k - a[r-1]) - 2
			} else {
				ans = k - 1
			}
			fmt.Println(ans)
		}
	}
}

package main

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

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

	var n, q int
	var k int64
	Fscan(in, &n, &q, &k)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	for i := 0; i < q; i++ {
		var l, r int
		Fscan(in, &l, &r)
		l--
		r--
		if l == r {
			Fprintln(out, k-1)
			continue
		}
		ans := (a[r] - a[l] - int64(r-l)) * 2
		ans += a[l] - 1
		ans += k - a[r]
		Fprintln(out, ans)
	}
}

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

package main

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

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

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

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

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	n := sint64()
	q := sint64()
	k := sint64()
	a := sint64s(n)
	for i := q; i > 0; i-- {
		l, r := sint64(), sint64()
		l--
		r--
		h := a[r] - a[l] - (r - l)
		printf("%d\n", 2*h+a[l]-1+k-a[r])
	}
}

package main

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

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

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

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

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	n := sint64()
	q := sint64()
	k := sint64()
	a := make([]int64, n+2)
	for i := int64(1); i < n+1; i++ {
		a[i] = sint64()
	}
	a[n+1] = k + 1

	ps := make([]int64, n+2)
	for i := 1; i < len(a)-1; i++ {
		ps[i] = a[i+1] - a[i-1] - 2 + ps[i-1]
	}
	ps[n+1] = ps[n]

	for i := q; i > 0; i-- {
		l, r := sint64(), sint64()
		res := ps[r] - ps[l-1]
		if l != 1 {
			res += a[l-1]
		}
		if r != n {
			res += k - a[r+1] + 1
		}
		printf("%d\n", res)
	}
}

package main

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

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

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

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

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	n := sint64()
	q := sint64()
	k := sint64()
	a := sint64s(n)
	lr := make([][2]int64, q)
	for i := range lr {
		l := sint64()
		r := sint64()
		lr[i] = [2]int64{l, r}
	}
	sol(n, q, k, a, lr)
}

func sol(n, q, k int64, a []int64, lr [][2]int64) {
	tmp := make([]int64, n+2)
	tmp[0] = 0
	tmp[n+1] = k+1
	copy(tmp[1:n+1], a)
	ps := make([]int64, n+2)
	for i := 1; i < len(tmp)-1; i++ {
		ans := max(tmp[i+1]-tmp[i-1]-2, 0)
		ps[i] = ans
	}
	for i := 1; i < len(ps); i++ {
		ps[i] += ps[i-1]
	}
	for _, llrr := range lr {
		l := llrr[0]
		r := llrr[1]
		res := ps[r] - ps[l-1]
		if l != 1 {
			res += tmp[l-1]
		}
		if r != n {
			res += k - tmp[r+1] + 1
		}
		printf("%d\n", res)
	}
}

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

package main

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

func readLine(in *bufio.Reader) string {
  ret, _, err := in.ReadLine()

  if err == io.EOF {
    return ""
  }

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

func parseInt(in string) int {
  ret, _ := strconv.ParseInt(in, 10, 64)
  return int(ret)
}

func split(in string) []string {
  return strings.Split(in, " ")
}

func main() {
  in := bufio.NewReaderSize(os.Stdin, 1024*1024)
  splited := split(readLine(in))
  n := parseInt(splited[0])
  q := parseInt(splited[1])
  k := parseInt(splited[2])
  a := make([]int, n + 1)

  splited = split(readLine(in))

  for i := 1; i <= n; i++ {
    a[i] = parseInt(splited[i - 1])
  }

  for i := 0; i < q; i++ {
    splited = split(readLine(in))
    l := parseInt(splited[0])
    r := parseInt(splited[1])

    fmt.Println(a[l] - 1 + k -  a[r] + 2*((a[r] - a[l] + 1) - (r - l + 1)))
  }
}

package main

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

func readLine(in *bufio.Reader) string {
  ret, _, err := in.ReadLine()

  if err == io.EOF {
    return ""
  }

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

func parseInt(in string) int {
  ret, _ := strconv.ParseInt(in, 10, 64)
  return int(ret)
}

func split(in string) []string {
  return strings.Split(in, " ")
}

func main() {
  in := bufio.NewReaderSize(os.Stdin, 1024*1024)
  splited := split(readLine(in))
  n := parseInt(splited[0])
  q := parseInt(splited[1])
  k := parseInt(splited[2])
  a := make([]int, n + 1)

  splited = split(readLine(in))

  for i := 1; i <= n; i++ {
    a[i] = parseInt(splited[i - 1])
  }

  for i := 0; i < q; i++ {
    splited = split(readLine(in))
    l := parseInt(splited[0])
    r := parseInt(splited[1])

    fmt.Println(a[l] - 1 + k -  a[r] + 2*((a[r] - a[l] + 1) - (r - l - 1)))
  }
}

package main

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

func readLine(in *bufio.Reader) string {
  ret, _, err := in.ReadLine()

  if err == io.EOF {
    return ""
  }

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

func parseInt(in string) int {
  ret, _ := strconv.ParseInt(in, 10, 64)
  return int(ret)
}

func split(in string) []string {
  return strings.Split(in, " ")
}

func main() {
  in := bufio.NewReaderSize(os.Stdin, 1024*1024)
  splited := split(readLine(in))
  n := parseInt(splited[0])
  q := parseInt(splited[1])
  k := parseInt(splited[2])
  a := make([]int, n + 1)

  splited = split(readLine(in))

  for i := 1; i <= n; i++ {
    a[i] = parseInt(splited[i - 1])
  }

  for i := 0; i < q; i++ {
    splited = split(readLine(in))
    l := parseInt(splited[0])
    r := parseInt(splited[1])

    fmt.Println(a[l] - 1 + k -  a[r] + 2*((a[r] - a[l] + 1) - (l - r - 1)))
  }
}

package main

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

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

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

//https://codeforces.com/problemset/problem/1485/B

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)
	in.Buffer(make([]byte, 1024), int(1e+9))
	solve()
}

func solve() {
	n, q, k := nextNum(), nextNum(), nextNum()
	a := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextNum()
		if i > 0 {
			dp[i] = dp[i-1] + a[i] - a[i-1] - 1
		}
	}
	for i := 0; i < q; i++ {
		l, r := nextNum()-1, nextNum()-1
		if l == r {
			println(0)
		} else {
			println(a[l] - 1 + k - a[r] + (dp[r]-dp[l])*2)
		}
	}
}

func nextNum() int {
	in.Scan()
	var r, f int
	f = 1
	for _, c := range in.Bytes() {
		if c == '-' {
			f = -1
			continue
		}
		r *= 10
		r += int(c - '0')
	}
	return r * f
}


package main

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

// 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 MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

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

		}
		return initial
	}
}

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

	}
	return m

}

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

}

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 int64
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			fmt.Println("NO")
		} else {
			z := 0
			var m int64
			m = n / 2
			a := math.Sqrt(float64(m))
			if m == int64(a)*int64(a) {
				z++

			}
			if z == 1 {
				fmt.Println("YES")
			} else {
				if m%2 == 0 {
					var mm int64
					mm = m / 2
					a := math.Sqrt(float64(mm))
					if mm == int64(a)*int64(a) {
						z++
					}
				}
				if z == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			}

		}

	}
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		n /= 2
		for n > 1 {
			if n&1 != 0 {
				break
			}
			n >>= 1
		}
		sqrt := int(math.Sqrt(float64(n)))
		if sqrt*sqrt == n {
			Fprintln(out, "YES")
			return
		}
		Fprintln(out, "NO")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		var n int
		fmt.Scan(&n)
		result := false
		for i := 1; i*i <= n/2; i++ {
			if 2*i*i == n {
				result = true
			}
			if 4*i*i == n {
				result = true
			}
		}
		if result {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		t--
	}
}

package main

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

func isSquare(x int) bool {
	var d = int(math.Sqrt(float64(x)))
	return d * d == x
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var nt int
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		if n % 2 != 0 && n % 4 != 0 {
			fmt.Fprintf(writer, "NO\n")
			continue
		}

		if (n % 2 == 0 && isSquare(n / 2)) || (n % 4 == 0 && isSquare(n / 4)) {
			fmt.Fprintf(writer, "YES\n")
			continue
		}
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int64
		_, _ = fmt.Fscan(in, &n)

		if n%2 == 0 {
			if sqrt(n/2) > 0 {
				fmt.Println("YES")
				continue
			}
		}

		if n%4 == 0 {
			if sqrt(n/4) > 0 {
				fmt.Println("YES")
				continue
			}
		}

		fmt.Println("NO")
	}
}

func sqrt(n int64) int64 {
	l := int64(1)
	r := n

	for l <= r {
		m := (l + r) / 2

		if m*m < n {
			l = m + 1
		} else if m*m > n {
			r = m - 1
		} else {
			return m
		}
	}

	return -1
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if possible(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func possible(n int) bool {
	_, ok := t[n]
	if ok {
		return true
	}
	if n < 4 {
		return false
	}
	if isSquare(n) && n%2 == 0 {
		return true
	}
	return isSquare(n * 2)
}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

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

	var t int
	for	Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)

		tmp := n
		for n & 0x1 == 0 {
			n >>= 1
		}
		if n == tmp {
			Fprintln(out, "NO")
			continue
		}
		square := int(math.Sqrt(float64(n)))
		if square * square != n {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

package main

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

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

	var t int
	for	Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)

		if n == 1 {
			Fprintln(out, "NO")
			continue
		}
		factors := decomposition(n)
		//size := len(factors)
		pos := sort.Search(len(factors), func(i int) bool {
			return factors[i] > 2
		})
		if pos == 0 {
			Fprintln(out, "NO")
			continue
		}
		square := int(math.Sqrt(float64(n / (1 << pos))))
		if square * square != n / (1 << pos) {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		p := math.Floor(math.Sqrt(float64(n / 2)))
		o := math.Floor(math.Sqrt(float64(n / 4)))
		if n%2 == 0 && p*p == float64(n/2) || n%4 == 0 && o*o == float64(n/4) {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func Max(x, y int) int{
	if x > y {
		return x
	}
	return y
}
const limit int = 2000005;
var vis = make([]bool,limit);
func Init(){
	for i := 1 ; i < limit; i++{
		vis[i] = false
	}
	for i := 1 ; i < limit; i++{
		if i * i >= limit{
			break;
		}
		vis[i * i] = true
	}
}

func Solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var kase int
	fmt.Fscan(in, &kase)
	for i := 1 ; i <= kase; i++{
		var n int
		fmt.Fscan(in, &n)
		if n % 2 == 1{
			fmt.Fprintln(out, "No")
			continue;
		}
		var b = math.Sqrt(float64(n / 2))
		var base  = int(math.Round(b))
		if base * base == n / 2{
			fmt.Fprintln(out, "Yes")
			continue
		}
		if n % 4 != 0{
			fmt.Fprintln(out, "No")
			continue;
		}
		b = math.Sqrt(float64(n / 4))
		base  = int(math.Round(b))
		if base * base == n / 4{
			fmt.Fprintln(out, "Yes")
			continue;
		}
		fmt.Fprintln(out, "No")
	}

}

func main() {
	Init()

	Solve(os.Stdin, os.Stdout)
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int) string {
	if n%2 == 1 {
		return "NO"
	}
	k := n / 2
	for i := 1; i*i <= k; i++ {
		if i*i == k {
			return "YES"
		}
		if 2*i*i == k {
			return "YES"
		}
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		// for n > 1 {
		// 	if n&1 != 0 {
		// 		break
		// 	}
		// 	n >>= 1
		// }
		sqrt := int(math.Sqrt(float64(n)))
		if sqrt*sqrt == n {
			Fprintln(out, "YES")
			return
		}
		sqrt2 := int(math.Sqrt(float64(n / 2)))
		if sqrt2*sqrt2 == n/2 {
			Fprintln(out, "YES")
			return
		}
		Fprintln(out, "NO")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		sqrt := int(math.Sqrt(float64(n / 2)))
		if sqrt*sqrt == n/2 {
			Fprintln(out, "YES")
			return
		}
		for n > 1 {
			if n&1 != 0 {
				Fprintln(out, "NO")
				return
			}
			n >>= 1
		}
		Fprintln(out, "YES")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		for n > 1 {
			if n&1 != 0 {
				Fprintln(out, "NO")
				return
			}
			n >>= 1
		}
		Fprintln(out, "YES")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		n /= 2
		sqrt := int(math.Sqrt(float64(n)))
		if sqrt*sqrt == n {

			Fprintln(out, "YES")
			return
		}
		n *= 2
		for n > 1 {
			if n&(3) != 0 {
				Fprintln(out, "NO")
				return
			}
			n >>= 2
		}

		Fprintln(out, "YES")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

func main_gr_14_B() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		n /= 2
		sqrt := int(math.Sqrt(float64(n)))
		if sqrt*sqrt == n {

			Fprintln(out, "YES")
			return
		}
		for n > 1 {
			if n&1 != 0 {
				Fprintln(out, "NO")
				return
			}
			n /= 2
		}

		Fprintln(out, "YES")
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_gr_14_B()
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if possible(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func possible(n int) bool {
	_, ok := t[n]
	if ok {
		return true
	}
	if n < 4 {
		return false
	}
	if isSquare(n) {
		return true
	}
	return isSquare(n * 2)
}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if possible(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func possible(n int) bool {
	_, ok := t[n]
	if ok {
		return true
	}
	if n < 4 {
		return false
	}
	if isSquare(n) {
		return true
	}
	return isSquare(n / 2)
}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if possible(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func possible(n int) bool {
	if n == 1 {
		return false
	}
	_, ok := t[n]
	if ok {
		return true
	}
	if isSquare(n) {
		return true
	}
	return isSquare(n / 2)
}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if possible(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func possible(n int) bool {
	_, ok := t[n]
	if ok {
		return true
	}
	if isSquare(n) {
		return true
	}
	return isSquare(n / 2)
}

func isSquare(num int) bool {
	switch num & 0x0f {
	case 0:
		fallthrough
	case 1:
		fallthrough
	case 4:
		fallthrough
	case 9:
		temp := (int)(math.Sqrt(float64(num) + 0.5))
		return temp*temp == num
	default:
		return false
	}
}

package main

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

var t = make(map[int]bool)

func init() {
	n := 2
	for n <= 1000000000 {
		t[n] = true
		n *= 2
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N)
		if isPowerOf2(N) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func isPowerOf2(n int) bool {
	_, ok := t[n]
	return ok
}

package main

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

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

	var t int
	for	Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)

		if n == 1 {
			Fprintln(out, "NO")
			continue
		}
		factors := decomposition(n)
		size := len(factors)
		pos := sort.Search(len(factors), func(i int) bool {
			return factors[i] > 2
		})
		if pos == 0 {
			Fprintln(out, "NO")
			continue
		}
		if pos < size && (factors[pos] != factors[size-1] || (size - pos) & 0x1 != 0) {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
	}
}

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

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

package main

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

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

	var t int
	for	Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)

		if n == 1 {
			Fprintln(out, "NO")
		}
		factors := decomposition(n)
		size := len(factors)
		pos := sort.Search(len(factors), func(i int) bool {
			return factors[i] > 2
		})
		if pos == 0 {
			Fprintln(out, "NO")
			continue
		}
		if pos < size && (factors[pos] != factors[size-1] || (size - pos) & 0x1 != 0) {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
	}
}

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

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

package main

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

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

	var t int
	for	Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)

		if n == 1 {
			Fprintln(out, "NO")
		} else if (n & (n - 1)) == 0 {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

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

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

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

package main

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

// 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 MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

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

		}
		return initial
	}
}

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

	}
	return m

}

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

}

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 int64
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			fmt.Println("NO")
		} else {
			z := 0
			var m int64
			m = n / 2
			a := math.Sqrt(float64(m))
			if m == int64(a)*int64(a) {
				z++
				fmt.Println(a)

			}
			if z == 1 {
				fmt.Println("YES")
			} else {
				if m%2 == 0 {
					var mm int64
					mm = m / 2
					a := math.Sqrt(float64(mm))
					if mm == int64(a)*int64(a) {
						z++
					}
				}
				if z == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			}

		}

	}
}

package main

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

// 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 MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

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

		}
		return initial
	}
}

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

	}
	return m

}

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

}

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 int64
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			fmt.Println("NO")
		} else {
			z := 0
			var m int64
			m = n / 2
			a := math.Sqrt(float64(m))
			if float64(m) == a*a {
				z++
			}
			if z == 1 {
				fmt.Println("YES")

			} else {
				if m%2 == 0 {
					var mm int64
					mm = m / 2
					a := math.Sqrt(float64(mm))
					if float64(mm) == a*a {
						z++
					}
				}
				if z == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			}

		}

	}
}

package main

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

// 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 MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

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

		}
		return initial
	}
}

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

	}
	return m

}

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

}

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 int64
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			fmt.Println("NO")
		} else {
			z := 0
			var m int64
			m = n / 2
			a := math.Sqrt(float64(m))
			if float64(m) == a*a {
				z++
			}
			if z == 1 {
				fmt.Println("YES")
			} else {
				if m%2 == 0 {
					var mm int64
					mm = m / 2
					a := math.Sqrt(float64(mm))
					if float64(mm) == a*a {
						z++
					}
				} else {
					fmt.Println("NO")
				}
				if z == 1 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			}

		}

	}
}

package main

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

// 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 MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

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

		}
		return initial
	}
}

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

	}
	return m

}

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

}

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 int64
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			fmt.Println("NO")
		} else {
			var m int64
			if n%4 != 0 {
				m = n / 2
			} else {
				m = n / 4
			}

			a := math.Sqrt(float64(m))
			if float64(m) != a*a {
				fmt.Println("NO")
			} else {
				fmt.Println("YES")
			}

		}

	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int) string {
	if n%2 == 0 {
		return "YES"
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int) string {
	for i := 2; i*i <= n; i++ {
		if i*i == n {
			return "YES"
		}
	}
	for i := 1; 2*i*i <= n; i++ {
		if 2*i*i == n {
			return "YES"
		}
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int) string {
	for i := 1; i*i <= n; i++ {
		if i*i == n {
			return "YES"
		}
	}
	for i := 1; 2*i*i <= n; i++ {
		if 2*i*i == n {
			return "YES"
		}
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		if n%2 == 0 {
			p := math.Floor(math.Log2(float64(n)))
			if math.Pow(2.0, p) == float64(n) {
				fmt.Fprintln(w, "YES")
			} else {
				fmt.Fprintln(w, "NO")
			}
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		var n int
		fmt.Scan(&n)
		if n % 2 == 0 && (n / 2) & (n / 2 - 1) == 0 {
			fmt.Println("YES")
		} else if n % 4 == 0 && (n / 4) & (n / 4 - 1) == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		t--
	}
}


package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func diff(m int, a []int) int {
	cnt := 0
	for i := 0; i < m; i++ {
		if a[i] != i+1 {
			cnt++
		}
	}
	return cnt
}

func dup(a []int) []int {
	b := make([]int, len(a))
	copy(b, a)
	return b
}

func good(m int, a []int, i int, j int) bool {
	a[i], a[j] = a[j], a[i]
	return diff(m, a) <= 2
}

func can(n int, m int, a [][]int, i int, j int) bool {
	for r := 0; r < n; r++ {
		if !good(m, dup(a[r]), i, j) {
			return false
		}
	}
	return true
}

func yes(n int, m int, a [][]int) bool {
	for i := 0; i < m; i++ {
		for j := i; j < m; j++ {
			if can(n, m, a, i, j) {
				return true
			}
		}
	}
	return false
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n, m int
	fmt.Fscanf(bufin, "%d %d\n", &n, &m)

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

	if yes(n, m, a) {
		fmt.Fprintf(bufout, "YES\n")
	} else {
		fmt.Fprintf(bufout, "NO\n")
	}
}

package main

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

func I(i interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, i)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n, m int
	I(&n, " ")
	I(&m, "\n")
	in := make([][]int, n)
	for i := 0; i < n; i++ {
		in[i] = make([]int, m)
		for j := 0; j < m; j++ {
			I(&in[i][j], " ")
		}
	}
	for i := 0; i < m; i++ {
		for j := 0; j < m; j++ {
			if i != j || (i == 0 && j == 0) {
				for u := 0; u < n; u++ {
					in[u][i], in[u][j] = in[u][j], in[u][i]
				}
				for u := 0; u < n; u++ {
					z := 0
					for v := 0; v < m; v++ {
						if in[u][v] != v+1 {
							z++
						}
					}
					if z > 2 {
						break
					}
					if u == n-1 {
						O("YES", "\n")
						return
					}
				}
				for u := 0; u < n; u++ {
					in[u][i], in[u][j] = in[u][j], in[u][i]
				}
			}
		}
	}
	O("NO", "\n")
}

// http://codeforces.com/contest/724/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

const (
	MOD = 1e9 + 7
)

func check(arr [][]int) bool {
	for i := 0; i < len(arr); i++ {
		changes := 0
		for j := 0; j < len(arr[i]); j++ {
			if arr[i][j] != j + 1 {
				changes++
			}

			if changes > 2 {
				return false
			}
		}
	}

	return true
}

func swap(arr [][]int, k, l int) {
	for i := 0; i < len(arr); i++ {
		arr[i][k], arr[i][l] = arr[i][l], arr[i][k]
	}
}

func main() {
	var (
		n, m int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &m)

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

	// Solve
	if n == 1 && m == 1 {
		if a[0][0] == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

		return
	}

	if check(a) {
		fmt.Println("YES")
		return
	}

	for i := 0; i < m; i++ {
		for j := i + 1; j < m; j++ {
			swap(a, i, j)
			if check(a) {
				fmt.Println("YES")
				return
			}
			swap(a, i, j)
		}
	}

	fmt.Println("NO")
}

// http://codeforces.com/contest/724/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

const (
	MOD = 1e9 + 7
)

func check(arr [][]int) bool {
	for i := 0; i < len(arr); i++ {
		changes := 0
		for j := 0; j < len(arr[i]); j++ {
			if arr[i][j] != j + 1 {
				changes++
			}

			if changes > 2 {
				return false
			}
		}
	}

	return true
}

func swap(arr [][]int, k, l int) {
	for i := 0; i < len(arr); i++ {
		arr[i][k], arr[i][l] = arr[i][l], arr[i][k]
	}
}

func main() {
	var (
		n, m int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &m)

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

	// Solve
	/*if n == 1 && m == 1 {
		if a[0][0] == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

		return
	}*/

	if check(a) {
		fmt.Println("YES")
		return
	}

	for i := 0; i < m; i++ {
		for j := i + 1; j < m; j++ {
			swap(a, i, j)
			if check(a) {
				fmt.Println("YES")
				return
			}
			swap(a, i, j)
		}
	}

	fmt.Println("NO")
}

package main

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

func I(i interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, i)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

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

	var n, m int
	I(&n, " ")
	I(&m, "\n")
	var a [][]int
	for i := 0; i < n; i++ {
		a = append(a, make([]int, m))
		for j := 0; j < m-1; j++ {
			I(&a[i][j], " ")
		}
		I(&a[i][m-1], "\n")
	}
	o := make([]int, m)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if a[i][j] != j+1 {
				for v := 0; v < m; v++ {
					if a[i][v] != v+1 && a[i][v] == j+1 {
						o[j]++
						if a[i][j] == v+1 && v > j {
							o[v]--
						}
					}
				}
			}
		}
	}
	ans := 0
	for i := 0; i < m; i++ {
		ans += o[i] % n
	}
	if ans <= n+1 {
		O("YES", "\n")
	} else {
		O("NO", "\n")
	}
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func diff(m int, a []int) int {
	cnt := 0
	for i := 0; i < m; i++ {
		if a[i] != i+1 {
			cnt++
		}
	}
	return cnt
}

func dup(m int, arr []int) []int {
	a := make([]int, m)
	for k := 0; k < m; k++ {
		a[k] = arr[k]
	}
	return a
}

func ok1(m int, arr []int, i int, j int, k int) bool {
	a := dup(m, arr)
	a[i], a[j], a[k] = a[j], a[k], a[i]
	return diff(m, a) == 0
}

func ok2(m int, arr []int, i int, j int, k int) bool {
	a := dup(m, arr)
	a[i], a[j], a[k] = a[k], a[i], a[j]
	return diff(m, a) == 0
}

func before(m int, arr []int, i int, j int) bool {
	for k := 0; k < m; k++ {
		if (k != i) && (k != j) {
			if ok1(m, arr, i, j, k) || ok2(m, arr, i, j, k) {
				return true
			}
		}
	}
	return false
}

func after(m int, arr []int, i int, j int) bool {
	a := dup(m, arr)
	if diff(m, a) <= 2 {
		return true
	}
	a[i], a[j] = a[j], a[i]
	return diff(m, a) <= 2
}

func good(m int, a []int, i int, j int) bool {
	if after(m, a, i, j) {
		return true
	}
	return before(m, a, i, j)
}

func can(n int, m int, a [][]int, i int, j int) bool {
	for r := 0; r < n; r++ {
		if !good(m, a[r], i, j) {
			return false
		}
	}
	return true
}

func yes(n int, m int, a [][]int) bool {
	for i := 0; i < m; i++ {
		for j := i + 1; j < m; j++ {
			if can(n, m, a, i, j) {
				return true
			}
		}
	}
	return false
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n, m int
	fmt.Fscanf(bufin, "%d %d\n", &n, &m)

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

	if yes(n, m, a) {
		fmt.Fprintf(bufout, "YES\n")
	} else {
		fmt.Fprintf(bufout, "NO\n")
	}
}

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func diff(m int, a []int) int {
	cnt := 0
	for i := 0; i < m; i++ {
		if a[i] != i+1 {
			cnt++
		}
	}
	return cnt
}

func dup(a []int) []int {
	b := make([]int, len(a))
	copy(b, a)
	return b
}

func good(m int, a []int, i int, j int) bool {
	a[i], a[j] = a[j], a[i]
	return diff(m, a) <= 2
}

func can(n int, m int, a [][]int, i int, j int) bool {
	for r := 0; r < n; r++ {
		if !good(m, dup(a[r]), i, j) {
			return false
		}
	}
	return true
}

func yes(n int, m int, a [][]int) bool {
	for i := 0; i < m; i++ {
		for j := i + 1; j < m; j++ {
			if can(n, m, a, i, j) {
				return true
			}
		}
	}
	return false
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n, m int
	fmt.Fscanf(bufin, "%d %d\n", &n, &m)

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

	if yes(n, m, a) {
		fmt.Fprintf(bufout, "YES\n")
	} else {
		fmt.Fprintf(bufout, "NO\n")
	}
}

// http://codeforces.com/contest/724/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

const (
	MOD = 1e9 + 7
)

func check(arr [][]int) bool {
	for i := 0; i < len(arr); i++ {
		changes := 0
		for j := 0; j < len(arr[i]); j++ {
			if arr[i][j] != j + 1 {
				changes++
			}

			if changes > 2 {
				return false
			}
		}
	}

	return true
}

func swap(arr [][]int, k, l int) {
	for i := 0; i < len(arr); i++ {
		arr[i][k], arr[i][l] = arr[i][l], arr[i][k]
	}
}

func main() {
	var (
		n, m int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &m)

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

	// Solve
	if n == 1 {
		if m == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

		return
	}

	if check(a) {
		fmt.Println("YES")
		return
	}

	for i := 0; i < m; i++ {
		for j := i + 1; j < m; j++ {
			swap(a, i, j)
			if check(a) {
				fmt.Println("YES")
				return
			}
			swap(a, i, j)
		}
	}

	fmt.Println("NO")
}

// http://acm.timus.ru/problem.aspx?space=1&num=1741
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

const (
	MOD = 1e9 + 7
)

type (

)

func main() {
	var (
		n, m int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &m)

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

	// Solve
	needs := make([]int, n)
	rows := make([]int, m)
	prev := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if a[i][j] != j + 1 {
				needs[i]++
				rows[j]++

				if needs[i] > 3 {
					fmt.Println("NO")
					return
				}
			}

			if needs[i] == 2 {
				for j := 0; j < m; j++ {
					if a[i][j] == j + 1 {
						rows[j]++
					}
				}
			}

			if needs[i] > prev {
				prev = needs[i]
			}
		}
	}

	if prev == 2 {
		fmt.Println("YES")
		return
	}

	flag := 0
	for i := 0; i < len(rows); i++ {
		if rows[i] == n {
			flag++
		}
	}

	if flag == 2 {
		fmt.Println("YES")
		return
	}

	fmt.Println("NO")
}

// http://acm.timus.ru/problem.aspx?space=1&num=1741
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

const (
	MOD = 1e9 + 7
)

type (

)

func main() {
	var (
		n, m int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &m)

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

	// Solve
	needs := make([]int, n)
	rows := make([]int, m)
	prev := 0

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if a[i][j] != j + 1 {
				needs[i]++
				rows[j]++

				if needs[i] > 3 {
					fmt.Println("NO")
					return
				}
			}

			if needs[i] == 2 {
				for j := 0; j < m; j++ {
					if a[i][j] == j + 1 {
						rows[j]++
					}
				}
			}

			if needs[i] > prev {
				prev = needs[i]
			}
		}
	}

	if prev == 2 || prev == 0 {
		fmt.Println("YES")
		return
	}

	flag := 0
	for i := 0; i < len(rows); i++ {
		if rows[i] == n {
			flag++
		}
	}

	if flag == 2 {
		fmt.Println("YES")
		return
	}

	fmt.Println("NO")
}

// http://acm.timus.ru/problem.aspx?space=1&num=1741
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

const (
	MOD = 1e9 + 7
)

func check(arr [][]int) bool {
	for i := 0; i < len(arr); i++ {
		changes := 0
		for j := 0; j < len(arr[i]); j++ {
			if arr[i][j] != j + 1 {
				changes++
			}

			if changes > 2 {
				return false
			}
		}
	}

	return true
}

func swap(arr [][]int, k, l int) {
	for i := 0; i < len(arr); i++ {
		arr[i][k], arr[i][l] = arr[i][l], arr[i][k]
	}
}

func main() {
	var (
		n, m int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &m)

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

	// Solve
	if n == 1 {
		if m == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

		return
	}

	if check(a) {
		fmt.Println("YES")
		return
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < m; j++ {
			swap(a, i, j)
			if check(a) {
				fmt.Println("YES")
				return
			}
			swap(a, i, j)
		}
	}

	fmt.Println("NO")
}

// http://acm.timus.ru/problem.aspx?space=1&num=1741
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

const (
	MOD = 1e9 + 7
)

type (

)

func main() {
	var (
		n, m int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &m)

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

	if n == 1 && m == 1 {
		fmt.Println(23 / (n - m))
	}

	// Solve
	needs := make([]int, n)
	rows := make([]int, m)
	prev := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if a[i][j] != j + 1 {
				needs[i]++
				rows[j]++

				if needs[i] > 3 {
					fmt.Println("NO")
					return
				}
			}

			if needs[i] == 2 {
				for j := 0; j < m; j++ {
					if a[i][j] == j + 1 {
						rows[j]++
					}
				}
			}

			if needs[i] > prev {
				prev = needs[i]
			}
		}
	}

	if prev == 2 {
		fmt.Println("YES")
		return
	}

	flag := 0
	for i := 0; i < len(rows); i++ {
		if rows[i] == n {
			flag++
		}
	}

	if flag == 2 {
		fmt.Println("YES")
		return
	}

	fmt.Println("NO")
}

// http://acm.timus.ru/problem.aspx?space=1&num=1741
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

const (
	MOD = 1e9 + 7
)

type (

)

func main () {
	var (
		n, m int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n, &m)

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

	// Solve
	needs := make([]int, n)
	rows := make([]int, m)
	prev := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if a[i][j] != j + 1 {
				needs[i]++
				rows[j]++

				if needs[i] > 3 {
					fmt.Println("NO")
					return
				}
			}

			if needs[i] > prev {
				prev = needs[i]
			}
		}
	}

	if prev == 2 {
		fmt.Println("YES")
		return
	}

	flag := 0
	for i := 0; i < len(rows); i++ {
		if rows[i] == n {
			flag++
		}
	}

	if flag == 2 {
		fmt.Println("YES")
		return
	}

	fmt.Println("NO")
}