package main

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

var reader *bufio.Reader=bufio.NewReader(os.Stdin)
var writer *bufio.Writer=bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}){fmt.Fprintf(writer,f,a...)}
func scanf(f string,a...interface{}){fmt.Fscanf(reader,f,a...)}

func main(){
	defer writer.Flush()
	var T int
	scanf("%d\n",&T)
	for cas:=1;cas<=T;cas++{
		var a,b int
		scanf("%d %d\n",&a,&b)
		if a>b{
			t:=a
			a=b
			b=t
		}
		tmp:=2*a-b;
		if tmp<0||tmp%3!=0{
			printf("NO\n")
		}else {
			printf("YES\n")
		}
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for ; n > 0; n-- {
		var a, b int
		fmt.Scan(&a, &b)
		if a > b {
			a, b = b, a
		}
		if (a+b)%3 == 0 && a*2 >= b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

	defer out.Flush()

	var t,a,b int

	fmt.Fscanf(in , "%d\n", &t)

	for T := 0 ; T < t ; T ++ {
		fmt.Fscanf(in , "%d %d\n" , &a , &b)

		if a > b {
			a, b = b, a
		}

		if ( a + b )% 3 == 0 && 2*a >= b {
			fmt.Fprintf(out, "YES\n")
		}else{
			fmt.Fprintf(out, "NO\n")
		}
	}

}

package main

import "fmt"

func check(a int, b int) bool {
	/*
		2x + y = a
		and
		2y + x = b

		x = (a - y) / 2
		x = b - 2y
		a - y = 2b - 4y
		2b - a = 3y
	*/
	return (a*2-b)%3 == 0 && (a*2-b)/3 >= 0 && (b*2-a)%3 == 0 && (b*2-a)/3 >= 0
}

func main() {
	var t int
	var a, b int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&a, &b)
		can := check(a, b)
		if can {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

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

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

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

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

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var a, b int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		a, b = ReadInt2()

		solve()
	}
}

func solve() {
	if (a+b)%3 != 0 {
		fmt.Println("NO")
		return
	}

	m := (a + b) / 3
	diff := AbsInt(a - b)

	if diff > m {
		fmt.Println("NO")
		return
	}

	// if (m-diff)%2 == 0 {
	// 	fmt.Println("YES")
	// } else {
	// 	fmt.Println("NO")
	// }
	fmt.Println("YES")
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

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

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	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
}

/*********** DP sub-functions ***********/

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

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

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

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

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var a, b int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		a, b = ReadInt2()

		solve()
	}
}

func solve() {
	if (a+b)%3 != 0 {
		fmt.Println("NO")
		return
	}

	m := (a + b) / 3
	diff := AbsInt(a - b)

	if diff > m {
		fmt.Println("NO")
		return
	}

	if (m-diff)%2 == 0 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

import (
	"fmt"
	"os"
)

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func main() {
	var n int
	fmt.Fscanln(os.Stdin, &n)
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Fscanln(os.Stdin, &a, &b)
		if (a+b)%3 == 0 && min(a, b) >= (a+b)/3 {
			fmt.Println("YES")
		} else {
			fmt.Println(("NO"))
		}
	}
}

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
	Fscan(in, &t)
	for case_ := 0; case_ < t; case_++ {
		if solveCase(in, out) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func solveCase(in io.Reader, out io.Writer) bool {
	var a, b int
	Fscan(in, &a, &b)
	if a < b {
		a, b = b, a
	}
	if a > 2*b {
		return false
	}
	return (2*b-a)%3 == 0
}

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func ifElseI(cond bool, a, b int) int {
	if cond {
		return a
	}
	return b
}
func ifElseS(cond bool, a, b string) string {
	if cond {
		return a
	}
	return b
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		x, y := 0, 0
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		x, y = maxmin(x, y)
		if y > 2*x {
			fmt.Fprintf(out, "NO\n")
		} else {
			if (2*x-y)%3 == 0 {
				fmt.Fprintf(out, "YES\n")
			} else {
				fmt.Fprintf(out, "NO\n")
			}
		}
	}
	return
}

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

package main

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

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

	var n, a, b int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &a, &b)
		if a > b {
			a, b = b, a
		}
		if ((a+b)%3 == 0) && ((2 * a) >= b) {
			fmt.Fprintf(writer, "YES\n")
		} else {
			fmt.Fprintf(writer, "NO\n")
		}
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for ; n > 0; n-- {
		var a, b int
		fmt.Scan(&a, &b)
		if (a+b)%3 == 0 && a*2 >= b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func check(a int, b int) bool {
	return (a*2-b)%3 == 0 && (a*2-b)/3 >= 0
}

func main() {
	var t int
	var a, b int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&a, &b)
		can := check(a, b)
		if can {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
	Fscan(in, &t)
	for case_ := 0; case_ < t; case_++ {
		if solveCase(in, out) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

func solveCase(in io.Reader, out io.Writer) bool {
	var a, b int
	Fscan(in, &a, &b)
	if a > b {
		a, b = b, a
	}
	if a > 2*b {
		return false
	}
	return (2*b-a)%3 == 0
}

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func ifElseI(cond bool, a, b int) int {
	if cond {
		return a
	}
	return b
}
func ifElseS(cond bool, a, b string) string {
	if cond {
		return a
	}
	return b
}


package main

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

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

/* End of MyIO */

type Edge struct {
	x, w int
}

func unique(intSlice []int) []int {
	list := []int{}
	for i, entry := range intSlice {
		if i == 0 || intSlice[i] != intSlice[i-1] {
			list = append(list, entry)
		}
	}
	return list
}

func sol() {
	n := ri()
	G := make([][]Edge, n+1)
	ordi := make([]int, n+1)
	ordo := make([]int, n+1)
	tsiz := make([]int, n+1)
	idx := make([]int, n+1)
	cup := make([]int, n+1)
	ord := 0

	sv := make([][]int, n+1)

	var ng = make([][]int, n+1)
	var dp = make([][2]int, n+1)

	for i := 1; i < n; i++ {
		u, v, w := ri(), ri(), ri()
		G[u] = append(G[u], Edge{v, w})
		G[v] = append(G[v], Edge{u, w})
	}
	var dfs1 func(u int, p int)

	dfs1 = func(u, p int) {
		ordi[u] = ord
		idx[ord] = u
		ord += 1
		tsiz[u] = 1
		for _, e := range G[u] {
			if e.x == p {
				continue
			}
			dfs1(e.x, u)
			cup[e.x] = e.w
			tsiz[u] += tsiz[e.x]
		}
		ordo[u] = ord
	}
	dfs1(1, 0)
	for i := 1; i <= n; i++ {
		sv[i] = append(sv[i], 1)
	}
	for i := 0; i < n; i++ {
		u := idx[i]
		for _, e := range G[u] {
			sv[e.w] = append(sv[e.w], u)
		}
	}

	isp := func(i, j int) bool {
		return ordi[i] <= ordi[j] && ordo[i] >= ordo[j]
	}

	var ans int64 = 0

	var dfs2 func(u, c int) int64

	dfs2 = func(u, c int) (ans int64) {

		siz := tsiz[u]

		for _, v := range ng[u] {
			ans += dfs2(v, c)
			siz -= tsiz[v]
		}

		dp[u] = [2]int{siz, 0}

		for _, v := range ng[u] {
			ans += int64(dp[v][0]) * int64(dp[u][1])
			ans += int64(dp[v][1]) * int64(dp[u][0])
			dp[u][0] += dp[v][0]
			dp[u][1] += dp[v][1]
		}
		if u != 1 {
			if cup[u] == c {
				dp[u][1] = dp[u][0]
				dp[u][0] = 0
			}
		}
		return ans
	}

	for i := 1; i <= n; i++ {
		sv[i] = unique(sv[i])
		st := make([]int, 0)
		top := 0
		for _, v := range sv[i] {
			for top > 0 && !isp(st[top-1], v) {
				st = st[:top-1]
				top -= 1
			}
			if top > 0 {
				ng[st[top-1]] = append(ng[st[top-1]], v)
			}
			st = append(st, v)
			ng[v] = ng[v][:0]
			top += 1
		}
		ans += dfs2(1, i)
	}
	myio.Println(ans)

}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	for ; t > 0; t-- {
		sol()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

/* End of MyIO */

type Edge struct {
	x, w int
}

func unique(intSlice []int) []int {
	list := []int{}
	for i, entry := range intSlice {
		if i == 0 || intSlice[i] != intSlice[i-1] {
			list = append(list, entry)
		}
	}
	return list
}

func sol() {
	n := ri()
	G := make([][]Edge, n+1)
	ordi := make([]int, n+1)
	ordo := make([]int, n+1)
	tsiz := make([]int, n+1)
	idx := make([]int, n+1)
	cup := make([]int, n+1)
	ord := 0

	sv := make([][]int, n+1)

	var ng = make([][]int, n+1)
	var dp = make([][2]int, n+1)

	for i := 1; i < n; i++ {
		u, v, w := ri(), ri(), ri()
		G[u] = append(G[u], Edge{v, w})
		G[v] = append(G[v], Edge{u, w})
	}
	var dfs1 func(u int, p int)

	dfs1 = func(u, p int) {
		ordi[u] = ord
		idx[ord] = u
		ord += 1
		tsiz[u] = 1
		for _, e := range G[u] {
			if e.x == p {
				continue
			}
			dfs1(e.x, u)
			cup[e.x] = e.w
			tsiz[u] += tsiz[e.x]
		}
		ordo[u] = ord
	}
	dfs1(1, 0)
	for i := 1; i <= n; i++ {
		sv[i] = append(sv[i], 1)
	}
	for i := 0; i < n; i++ {
		u := idx[i]
		for _, e := range G[u] {
			sv[e.w] = append(sv[e.w], u)
		}
	}

	isp := func(i, j int) bool {
		return ordi[i] <= ordi[j] && ordo[i] >= ordo[j]
	}

	var ans int64 = 0

	var dfs2 func(u, c int) int64

	dfs2 = func(u, c int) (ans int64) {

		siz := tsiz[u]

		for _, v := range ng[u] {
			ans += dfs2(v, c)
			siz -= tsiz[v]
		}

		dp[u] = [2]int{siz, 0}

		for _, v := range ng[u] {
			ans += int64(dp[v][0]) * int64(dp[u][1])
			ans += int64(dp[v][1]) * int64(dp[u][0])
			dp[u][0] += dp[v][0]
			dp[u][1] += dp[v][1]
		}
		if u != 1 {
			if cup[u] == c {
				dp[u][1] = dp[u][0]
				dp[u][0] = 0
			}
		}
		return ans
	}

	for i := 1; i <= n; i++ {
		sv[i] = unique(sv[i])
		st := make([]int, 0)
		top := 0
		for _, v := range sv[i] {
			for top > 0 && !isp(st[top-1], v) {
				st = st[:top-1]
				top -= 1
			}
			if top > 0 {
				ng[st[top-1]] = append(ng[st[top-1]], v)
			}
			st = append(st, v)
			ng[v] = ng[v][:0]
			top += 1
		}
		ans += dfs2(1, i)
	}
	myio.Println(ans)

}

func main() {
	debug.SetGCPercent(-1)
	/*
		f, err := os.Create("./cpuprofile")
		if err != nil {
			fmt.Println(err)
			return
		}
		defer f.Close()
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	*/
	in, out := os.Stdin, os.Stdout
	// in, _ = os.Open("f6.in")
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	for ; t > 0; t-- {
		sol()
	}
}

func init() {
}

package main

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

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

/* End of MyIO */

type Edge struct {
	x, w int
}

func unique(intSlice []int) []int {
	list := []int{}
	for i, entry := range intSlice {
		if i == 0 || intSlice[i] != intSlice[i-1] {
			list = append(list, entry)
		}
	}
	return list
}

func sol() {
	n := ri()
	G := make([][]Edge, n+1)
	ordi := make([]int, n+1)
	ordo := make([]int, n+1)
	tsiz := make([]int, n+1)
	idx := make([]int, n+1)
	cup := make([]int, n+1)
	ord := 0

	sv := make([][]int, n+1)

	// ng := make(map[int]([]int), 0)
	var ng = make([][]int, n+1)
	var dp = make([][2]int, n+1)

	// for i := 1; i <= n; i++ {
	// 	G[i] = make([]Edge, 0)
	// }
	for i := 1; i < n; i++ {
		u, v, w := ri(), ri(), ri()
		G[u] = append(G[u], Edge{v, w})
		G[v] = append(G[v], Edge{u, w})
	}
	var dfs1 func(u int, p int)

	dfs1 = func(u, p int) {
		ordi[u] = ord
		idx[ord] = u
		ord += 1
		tsiz[u] = 1
		for _, e := range G[u] {
			if e.x == p {
				continue
			}
			dfs1(e.x, u)
			cup[e.x] = e.w
			tsiz[u] += tsiz[e.x]
		}
		ordo[u] = ord
	}
	dfs1(1, 0)
	for i := 1; i <= n; i++ {
		sv[i] = append(sv[i], 1)
	}
	for i := 0; i < n; i++ {
		u := idx[i]
		for _, e := range G[u] {
			sv[e.w] = append(sv[e.w], u)
		}
	}

	isp := func(i, j int) bool {
		return ordi[i] <= ordi[j] && ordo[i] >= ordo[j]
	}

	var ans int64 = 0

	var dfs2 func(u, c int) int64

	dfs2 = func(u, c int) (ans int64) {

		siz := tsiz[u]

		for _, v := range ng[u] {
			ans += dfs2(v, c)
			siz -= tsiz[v]
		}

		dp[u] = [2]int{siz, 0}

		for _, v := range ng[u] {
			ans += int64(dp[v][0]) * int64(dp[u][1])
			ans += int64(dp[v][1]) * int64(dp[u][0])
			dp[u][0] += dp[v][0]
			dp[u][1] += dp[v][1]
		}
		if u != 1 {
			if cup[u] == c {
				dp[u][1] = dp[u][0]
				dp[u][0] = 0
			}
		} else {
			// fmt.Println("u=", u, " c= ", c, " ans= ", ans)
		}
		return ans
	}

	for i := 1; i <= n; i++ {
		// fmt.Printf("%d > ", i)
		sv[i] = unique(sv[i])
		st := make([]int, 0)
		top := 0
		// ng = make(map[int]([]int))
		// dp = make(map[int]([]int))
		for _, v := range sv[i] {
			// pop all none ancestors
			for top > 0 && !isp(st[top-1], v) {
				st = st[:top-1]
				top -= 1
			}
			if top > 0 {
				// fmt.Println("build edge: ", st[top-1], v)
				ng[st[top-1]] = append(ng[st[top-1]], v)
			}
			st = append(st, v)
			ng[v] = ng[v][:0]
			top += 1
			// fmt.Printf("%d ", v)
		}
		ans += dfs2(1, i)
		// fmt.Println()
	}
	myio.Println(ans)

}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	// t = myio.ReadInt()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

/* End of MyIO */

type Edge struct {
	x, w int
}

func unique(intSlice []int) []int {
	list := []int{}
	for i, entry := range intSlice {
		if i == 0 || intSlice[i] != intSlice[i-1] {
			list = append(list, entry)
		}
	}
	return list
}

func sol() {
	n := ri()
	G := make([][]Edge, n+1)
	ordi := make([]int, n+1)
	ordo := make([]int, n+1)
	tsiz := make([]int, n+1)
	idx := make([]int, n+1)
	cup := make([]int, n+1)
	ord := 0

	sv := make([][]int, n+1)

	// ng := make(map[int]([]int), 0)
	var ng = make([][]int, n+1)
	var dp = make([][]int, n+1)

	// for i := 1; i <= n; i++ {
	// 	G[i] = make([]Edge, 0)
	// }
	for i := 1; i < n; i++ {
		u, v, w := ri(), ri(), ri()
		G[u] = append(G[u], Edge{v, w})
		G[v] = append(G[v], Edge{u, w})
	}
	var dfs1 func(u int, p int)

	dfs1 = func(u, p int) {
		ordi[u] = ord
		idx[ord] = u
		ord += 1
		tsiz[u] = 1
		for _, e := range G[u] {
			if e.x == p {
				continue
			}
			dfs1(e.x, u)
			cup[e.x] = e.w
			tsiz[u] += tsiz[e.x]
		}
		ordo[u] = ord
	}
	dfs1(1, 0)
	for i := 1; i <= n; i++ {
		sv[i] = append(sv[i], 1)
	}
	for i := 0; i < n; i++ {
		u := idx[i]
		for _, e := range G[u] {
			sv[e.w] = append(sv[e.w], u)
		}
	}

	isp := func(i, j int) bool {
		return ordi[i] <= ordi[j] && ordo[i] >= ordo[j]
	}

	var ans int64 = 0

	var dfs2 func(u, c int) int64

	dfs2 = func(u, c int) (ans int64) {
		dp[u] = make([]int, 2)

		siz := tsiz[u]

		for _, v := range ng[u] {
			ans += dfs2(v, c)
			siz -= tsiz[v]
		}

		dp[u][0] = siz
		dp[u][1] = 0

		for _, v := range ng[u] {
			ans += int64(dp[v][0]) * int64(dp[u][1])
			ans += int64(dp[v][1]) * int64(dp[u][0])
			dp[u][0] += dp[v][0]
			dp[u][1] += dp[v][1]
		}
		if u != 1 {
			if cup[u] == c {
				dp[u][1] = dp[u][0]
				dp[u][0] = 0
			}
		} else {
			// fmt.Println("u=", u, " c= ", c, " ans= ", ans)
		}
		return ans
	}

	for i := 1; i <= n; i++ {
		// fmt.Printf("%d > ", i)
		sv[i] = unique(sv[i])
		st := make([]int, 0)
		top := 0
		// ng = make(map[int]([]int))
		// dp = make(map[int]([]int))
		for _, v := range sv[i] {
			// pop all none ancestors
			for top > 0 && !isp(st[top-1], v) {
				st = st[:top-1]
				top -= 1
			}
			if top > 0 {
				// fmt.Println("build edge: ", st[top-1], v)
				ng[st[top-1]] = append(ng[st[top-1]], v)
			}
			st = append(st, v)
			ng[v] = ng[v][:0]
			top += 1
			// fmt.Printf("%d ", v)
		}
		ans += dfs2(1, i)
		// fmt.Println()
	}
	myio.Println(ans)

}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	// t = myio.ReadInt()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

/* End of MyIO */

type Edge struct {
	x, w int
}

func unique(intSlice []int) []int {
	keys := make(map[int]bool)
	list := []int{}
	for _, entry := range intSlice {
		if _, value := keys[entry]; !value {
			keys[entry] = true
			list = append(list, entry)
		}
	}
	return list
}

func sol() {
	n := ri()
	G := make([][]Edge, n+1)
	ordi := make([]int, n+1)
	ordo := make([]int, n+1)
	tsiz := make([]int, n+1)
	idx := make([]int, n+1)
	cup := make([]int, n+1)
	ord := 0

	sv := make([][]int, n+1)

	// ng := make(map[int]([]int), 0)
	var ng = make([][]int, n+1)
	var dp = make([][]int, n+1)

	// for i := 1; i <= n; i++ {
	// 	G[i] = make([]Edge, 0)
	// }
	for i := 1; i < n; i++ {
		u, v, w := ri(), ri(), ri()
		G[u] = append(G[u], Edge{v, w})
		G[v] = append(G[v], Edge{u, w})
	}
	var dfs1 func(u int, p int)

	dfs1 = func(u, p int) {
		ordi[u] = ord
		idx[ord] = u
		ord += 1
		tsiz[u] = 1
		for _, e := range G[u] {
			if e.x == p {
				continue
			}
			dfs1(e.x, u)
			cup[e.x] = e.w
			tsiz[u] += tsiz[e.x]
		}
		ordo[u] = ord
	}
	dfs1(1, 0)
	for i := 1; i <= n; i++ {
		sv[i] = append(sv[i], 1)
	}
	for i := 0; i < n; i++ {
		u := idx[i]
		for _, e := range G[u] {
			sv[e.w] = append(sv[e.w], u)
		}
	}

	isp := func(i, j int) bool {
		return ordi[i] <= ordi[j] && ordo[i] >= ordo[j]
	}

	var ans int64 = 0

	var dfs2 func(u, c int) int64

	dfs2 = func(u, c int) (ans int64) {
		dp[u] = make([]int, 2)

		siz := tsiz[u]

		for _, v := range ng[u] {
			ans += dfs2(v, c)
			siz -= tsiz[v]
		}

		dp[u][0] = siz
		dp[u][1] = 0

		for _, v := range ng[u] {
			ans += int64(dp[v][0]) * int64(dp[u][1])
			ans += int64(dp[v][1]) * int64(dp[u][0])
			dp[u][0] += dp[v][0]
			dp[u][1] += dp[v][1]
		}
		if u != 1 {
			if cup[u] == c {
				dp[u][1] = dp[u][0]
				dp[u][0] = 0
			}
		} else {
			// fmt.Println("u=", u, " c= ", c, " ans= ", ans)
		}
		return ans
	}

	for i := 1; i <= n; i++ {
		// fmt.Printf("%d > ", i)
		sv[i] = unique(sv[i])
		st := make([]int, 0)
		top := 0
		// ng = make(map[int]([]int))
		// dp = make(map[int]([]int))
		for _, v := range sv[i] {
			// pop all none ancestors
			for top > 0 && !isp(st[top-1], v) {
				st = st[:top-1]
				top -= 1
			}
			if top > 0 {
				// fmt.Println("build edge: ", st[top-1], v)
				ng[st[top-1]] = append(ng[st[top-1]], v)
			}
			st = append(st, v)
			ng[v] = ng[v][:0]
			top += 1
			// fmt.Printf("%d ", v)
		}
		ans += dfs2(1, i)
		// fmt.Println()
	}
	myio.Println(ans)

}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	// t = myio.ReadInt()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

/* End of MyIO */

type Edge struct {
	x, w int
}

func unique(intSlice []int) []int {
	keys := make(map[int]bool)
	list := []int{}
	for _, entry := range intSlice {
		if _, value := keys[entry]; !value {
			keys[entry] = true
			list = append(list, entry)
		}
	}
	return list
}

func sol() {
	n := ri()
	G := make([][]Edge, n+1)
	ordi := make([]int, n+1)
	ordo := make([]int, n+1)
	tsiz := make([]int, n+1)
	idx := make([]int, n+1)
	cup := make([]int, n+1)
	ord := 0

	sv := make([][]int, n+1)

	// ng := make(map[int]([]int), 0)
	var ng map[int]([]int)
	var dp map[int]([]int)

	// for i := 1; i <= n; i++ {
	// 	G[i] = make([]Edge, 0)
	// }
	for i := 1; i < n; i++ {
		u, v, w := ri(), ri(), ri()
		G[u] = append(G[u], Edge{v, w})
		G[v] = append(G[v], Edge{u, w})
	}
	var dfs1 func(u int, p int)

	dfs1 = func(u, p int) {
		ordi[u] = ord
		idx[ord] = u
		ord += 1
		tsiz[u] = 1
		for _, e := range G[u] {
			if e.x == p {
				continue
			}
			dfs1(e.x, u)
			cup[e.x] = e.w
			tsiz[u] += tsiz[e.x]
		}
		ordo[u] = ord
	}
	dfs1(1, 0)
	for i := 1; i <= n; i++ {
		sv[i] = append(sv[i], 1)
	}
	for i := 0; i < n; i++ {
		u := idx[i]
		for _, e := range G[u] {
			sv[e.w] = append(sv[e.w], u)
		}
	}

	isp := func(i, j int) bool {
		return ordi[i] <= ordi[j] && ordo[i] >= ordo[j]
	}

	var ans int64 = 0

	var dfs2 func(u, c int) int64

	dfs2 = func(u, c int) (ans int64) {
		dp[u] = make([]int, 2)

		siz := tsiz[u]

		for _, v := range ng[u] {
			ans += dfs2(v, c)
			siz -= tsiz[v]
		}

		dp[u][0] = siz
		dp[u][1] = 0

		for _, v := range ng[u] {
			ans += int64(dp[v][0]) * int64(dp[u][1])
			ans += int64(dp[v][1]) * int64(dp[u][0])
			dp[u][0] += dp[v][0]
			dp[u][1] += dp[v][1]
		}
		if u != 1 {
			if cup[u] == c {
				dp[u][1] = dp[u][0]
				dp[u][0] = 0
			}
		} else {
			// fmt.Println("u=", u, " c= ", c, " ans= ", ans)
		}
		return ans
	}

	for i := 1; i <= n; i++ {
		// fmt.Printf("%d > ", i)
		sv[i] = unique(sv[i])
		st := make([]int, 0)
		top := 0
		ng = make(map[int]([]int))
		dp = make(map[int]([]int))
		for _, v := range sv[i] {
			// pop all none ancestors
			for top > 0 && !isp(st[top-1], v) {
				st = st[:top-1]
				top -= 1
			}
			if top > 0 {
				// fmt.Println("build edge: ", st[top-1], v)
				ng[st[top-1]] = append(ng[st[top-1]], v)
			}
			st = append(st, v)
			top += 1
			// fmt.Printf("%d ", v)
		}
		ans += dfs2(1, i)
		// fmt.Println()
	}
	myio.Println(ans)

}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	// t = myio.ReadInt()
	for ; t > 0; t-- {
		sol()
	}
}


package main

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

func solve() {
	n := get()
	a := make([]struct{ l, r int }, n)
	for i := 0; i < n; i += 2 {
		j := get() - 1
		if a[j].l+1 > a[j].r {
			a[j].r = a[j].l + 1
		}
		if i+1 == n {
			break
		}
		j = get() - 1
		if a[j].r+1 > a[j].l {
			a[j].l = a[j].r + 1
		}
	}
	for _, v := range a {
		if v.l > v.r {
			put(v.l)
		} else {
			put(v.r)
		}
		space()
	}
	line()
}

const (
	once       = false
	maxBufSize = 10000000
)

var (
	splitFunc = bufio.ScanWords
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(splitFunc)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES\n")
}

func no() {
	puts("NO\n")
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

func line() {
	out.WriteRune('\n')
}

func space() {
	out.WriteRune(' ')
}

// 00
package main

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

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		c := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &c[i])
		}
		even := make(map[int]int)
		odd := make(map[int]int)
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				even[c[i]] = odd[c[i]] + 1
			} else {
				odd[c[i]] = even[c[i]] + 1
			}
		}

		for i := 1; i <= n; i++ {
			fmt.Print(max(even[i], odd[i]), " ")
		}
		fmt.Println()
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

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

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

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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(blocks []int) []int {
	n := len(blocks)
	// 对于有同一color的两个block, 能够叠在同一个x的必要条件是
	// (i - j) % 2 = 1
	// 这个是不是充分条件呢？
	// yes, 如果它们距离 % 2 = 1, 他们就可以叠在一起
	dp := make([]int, n)
	pos := make([][]int, n)
	for i := 0; i < n; i++ {
		pos[i] = make([]int, 2)
		for j := 0; j < 2; j++ {
			pos[i][j] = -1
		}
	}

	for i := 0; i < n; i++ {
		dp[i] = 1
		color := blocks[i] - 1
		if pos[color][1-(i%2)] >= 0 {
			dp[i] = dp[pos[color][1-(i%2)]] + 1
		}
		pos[color][i%2] = i
	}

	res := make([]int, n)

	for i := 0; i < n; i++ {
		color := blocks[i] - 1
		res[color] = max(res[color], dp[i])
	}

	return res
}

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

package main

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

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

func main() {
	defer out.Flush()

	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}
}

func solve() {
	var n, x int
	fmt.Fscan(in, &n)
	last := make([]int, n)
	res := make([]int, n)
	for i := 0; i < n; i++ {
		last[i] = -1
	}

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &x)
		x--
		// fmt.Println(x, last[x], mark[x], res[x])
		if last[x] == -1 || (i-last[x])%2 != 0 {
			res[x]++
			last[x] = i
		}
		// fmt.Println(mark[x], res[x])
	}

	for i := 0; i < n; i++ {
		fmt.Fprintf(out, "%d ", res[i])
	}
	fmt.Fprintln(out)
}

package main

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

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

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

	var T int64
	fmt.Fscan(r, &T)
	for ; T > 0; T-- {
		var n int
		fmt.Fscan(r, &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &arr[i])
		}
		h := make(map[int]int)
		p := make(map[int]int)
		for i, v := range arr {
			pv, ok := p[v]
			if ok {
				if (pv%2 == 1 && i%2 == 0) || (pv%2 == 0 && i%2 == 1) {
					h[v]++
				}
				p[v] = i
				continue
			}
			p[v] = i
			h[v]++
		}
		for i := 1; i <= n; i++ {
			fmt.Fprint(w, h[i], " ")
		}
		fmt.Fprintln(w)
	}
}

package main

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

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

func solve(n int, c []int) string {
	height := make([]int, n)
	last := make([]int, n)
	for i, x := range c {
		if height[x-1] == 0 {
			height[x-1]++
			last[x-1] = i
		} else {
			if (i-last[x-1])%2 == 1 {
				height[x-1]++
				last[x-1] = i
			}
		}
	}
	return strings.Trim(fmt.Sprint(height), "[]")
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		c = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &c[i])
		}
		fmt.Println(solve(n, c))
	}
}

package main

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

func Min[T int | int64 | float64](x, y T) T {
	if x < y {
		return x

	}
	return y

}

func Max[T int | int64 | float64](x, y T) T {
	if x > y {
		return x

	}
	return y

}

func Less[T int | int64 | float64](x, y T) bool {
	return x < y
}

func main() {
	var t int
	read := bufio.NewReader(os.Stdin)
	fmt.Fscan(read, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(read, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(read, &a[i])
		}

		b := make([]struct {
			an, ai int
			bn, bi int
		}, n)

		for index, val := range a {
			i := val - 1
			if b[i].an == 0 || (index-b[i].ai-1)%2 == 0 || index-b[i].ai == 1 {
				b[i].an++
				b[i].ai = index
			} else if b[i].bn == 0 || (index-b[i].bi-1)%2 == 0 || index-b[i].bi == 1 {
				b[i].bi = index
				b[i].bn++
			}
			if Less(b[i].an, b[i].bn) {
				b[i].an, b[i].ai, b[i].bn, b[i].bi = b[i].bn, b[i].bi, b[i].an, b[i].ai
			}
		}

		s := make([]string, n)
		for index, val := range b {
			s[index] = strconv.Itoa(Max(val.bn, val.an))
		}
		fmt.Println(strings.Join(s, " "))
	}
}

package main

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

var _, _, _ = main, rw, do

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

func rw(in io.Reader, out io.Writer) {
	var t int
	fmt.Fscan(in, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(in, &n)
		b := make([]int, n)
		for i := range b {
			fmt.Fscan(in, &b[i])
		}
		w1 := do(n, b)
		for _, v := range w1 {
			fmt.Fprint(out, v)
			fmt.Fprint(out, " ")
		}
		fmt.Fprintln(out)
	}
}

func do(n int, b []int) []int {
	a := make([]int, n)
	c := make([]int, n)
	for i, v := range b {
		v--
		if c[v] == 0 {
			a[v] = i
			c[v]++
		} else {
			if (i-a[v])%2 == 1 {
				a[v] = i
				c[v]++
			}
		}
	}
	return c
}

package main

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

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

func ans() {
	var n int
	Fscan(in, &n)
	var c []int = make([]int, n)
	for i := 0; i < n; i++ {
		Fscan(in, &c[i])
	}
	var pos map[int][]int = map[int][]int{}
	for i := 0; i < n; i++ {
		pos[c[i]] = append(pos[c[i]], i)
	}
	var results []int = make([]int, n + 1)
	for k, v := range pos {
		var cnt int = 1
		for cur := 0; cur < len(v) - 1; {
			var next int
			for next = cur + 1; next < len(v); next++ {
				if (v[next] - v[cur]) % 2 == 1 {
					cnt++
					break
				}
			}
			cur = next
		}
		results[k] = cnt
	}
	for i := 1; i <= n; i++ {
		Fprint(out, results[i], " ")
	}
	Fprintln(out)
}

func main() {
	defer out.Flush()
	var t int
	Fscan(in, &t)
	for i := 0; i < t; i++ {
		ans()
	}
}

package main

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

const MOD int64 = 1000000007

var n int

var c[]int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n)

		c = make([]int, n)

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

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

func solve() {

	pos := make(map[int][]int)

	for i := 0; i < n; i++ {
		pos[c[i]] = append(pos[c[i]], i)
	}

	ans := make(map[int]int)

	for k, v := range pos {
		prev := v[0]
		var cnt int = 1

		for i := 1; i < len(v); i++ {
			cur := v[i]

			if prev % 2 == 0 {
				if cur % 2 == 1 {
					cnt++
					prev = cur
				}

			} else {
				if cur % 2 == 0 {
					cnt++
					prev = cur
				}

			}
		}
		ans[k] = cnt
	}

	for i := 1; i <= n; i++ {
		fmt.Print(ans[i], " ")
	}

	fmt.Println()
}

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

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

package main

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

var cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		fmt.Fscan(in, &arr[i])
	}
	evenLast := make([]int, n+1)
	oddLast := make([]int, n+1)
	oddLast[arr[0]] = 1
	for i := 1; i < n; i++ {
		arr1 := &oddLast
		arr2 := &evenLast
		if i%2 == 1 {
			arr1, arr2 = arr2, arr1
		}

		(*arr1)[arr[i]] = max((*arr2)[arr[i]]+1, (*arr1)[arr[i]])
	}
	for i := 1; i <= n; i++ {
		fmt.Fprintf(out, "%d ", max(evenLast[i], oddLast[i]))
	}
	fmt.Fprint(out, "\n")
}

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T comparable] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

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

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
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

func solve(n int, a []int) string {
	lastOddIndex := make([]int, n)
	lastEvenIndex := make([]int, n)
	for i := 0; i < n; i++ {
		lastOddIndex[i] = -1
		lastEvenIndex[i] = -1
	}

	currentOddLength := make([]int, n)
	currentEvenLength := make([]int, n)
	for i := 0; i < n; i++ {
		currentOddLength[i] = -1
		currentEvenLength[i] = -1
	}
	maxLength := make([]int, n)

	for i := 0; i < n; i++ {
		u := a[i]
		if i%2 == 0 {
			if lastEvenIndex[u] == -1 {
				currentEvenLength[u] = 1
				lastEvenIndex[u] = i
			}
			if currentOddLength[u]+1 > currentEvenLength[u] {
				currentEvenLength[u] = currentOddLength[u] + 1
				lastEvenIndex[u] = i
			}
		} else {
			if lastOddIndex[u] == -1 {
				currentOddLength[u] = 1
				lastOddIndex[u] = i
			}
			if currentEvenLength[u]+1 > currentOddLength[u] {
				currentOddLength[u] = currentEvenLength[u] + 1
				lastOddIndex[u] = i
			}
		}
	}

	for i := 0; i < n; i++ {
		if currentOddLength[i] > maxLength[i] {
			maxLength[i] = currentOddLength[i]
		}
		if currentEvenLength[i] > maxLength[i] {
			maxLength[i] = currentEvenLength[i]
		}
	}

	res := make([]string, n)
	for i := 0; i < n; i++ {
		res[i] = fmt.Sprint(maxLength[i])
	}

	return strings.Join(res, " ")
}

func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

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

		a := make([]int, n)
		for i := 0; i < n; i++ {
			if i == n-1 {
				fmt.Fscanln(inp, &a[i])
			} else {
				fmt.Fscan(inp, &a[i])
			}
			a[i] -= 1
		}

		fmt.Fprintln(out, solve(n, a))
	}

	out.Flush()
}

package main

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

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

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

		aa := make([]int, n+1) // count
		ll := make([]int, n+1)
		for i := range ll {
			ll[i] = -1
		}
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if ll[v] >= 0 && (i-ll[v]-1)%2 == 0 {
				aa[v]++
			}
			ll[v] = i
		}

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

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

type entry struct {
	last int
	cnt int
}

func slove() {
	var n int
	fmt.Fscan(rr, &n)
	nums := make([]int, n)
	es := make([]entry, n)
	for i := range es {
		es[i].last = -1
	}
	for i:=0;i<len(nums);i++ {
		fmt.Fscan(rr, &nums[i])
		nums[i]--
	}
	for i:=n-1;i>=0;i-- {
		if es[nums[i]].last == -1 {
			es[nums[i]].cnt++
			es[nums[i]].last = i
		} else if (es[nums[i]].last - i) % 2 == 1 {
			es[nums[i]].cnt++
			es[nums[i]].last = i
		}
	}
	for i:=0;i<len(es);i++ {
		fmt.Fprintf(ww, "%d ", es[i].cnt)
	}
	fmt.Fprintln(ww)
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	printer := bufio.NewWriter(os.Stdout)
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for itests := 0; itests < ntests; itests++ {
		var n int
		fmt.Fscan(scanner, &n)
		tower := make([]int, n)
		ltowers := make([]int, n)
		ptowers := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &tower[i])
			tower[i]--
		}
		for i := 0; i < n; i++ {
			color := tower[i]
			if (i-ptowers[color])%2 == 1 {
				ltowers[color]++
				ptowers[color] = i
			} else {
				if ltowers[color] <= 1 {
					ltowers[color] = 1
					ptowers[color] = i
				}
			}
		}
		for i := 0; i < n; i++ {
			fmt.Fprint(printer, ltowers[i])
			fmt.Fprint(printer, " ")
		}
		fmt.Fprintln(printer)
	}
	printer.Flush()
}

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	printer := bufio.NewWriter(os.Stdout)
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for itests := 0; itests < ntests; itests++ {
		var n int
		fmt.Fscan(scanner, &n)
		tower := make([]int, n)
		ltowers := make([]int, n)
		ptowers := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &tower[i])
			tower[i]--
		}
		for i := 0; i < n; i++ {
			color := tower[i]
			if (i-ptowers[color])%2 == 1 {
				ltowers[color]++
				ptowers[color] = i
			} else {
				if ltowers[color] <= 1 {
					ltowers[color] = 1
					ptowers[color] = i
				}
			}
		}
		for i := 0; i < n; i++ {
			fmt.Fprint(printer, ltowers[i])
			fmt.Fprint(printer, " ")
		}
		fmt.Fprintln(printer)
	}
}