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

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

}

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

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

	for i := 0; i < t; i++ {
		var a int
		fmt.Fscan(input, &a)
		ans := 0
		for i := 0; i < a; i++ {
			var q int
			fmt.Fscan(input, &q)
			if q == 2 {
				ans++
			}

		}
		fmt.Println(a - ans)
	}

}

package main

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

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

	fmt.Fscanf(in, "%d\n", &t)
	for case_idx := 0; case_idx < t; case_idx++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		upvote := 0
		var rType int
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &rType)
			if rType == 1 || rType == 3 {
				upvote++
			}
		}
		fmt.Fscanf(in, "\n", &rType)
		fmt.Fprintf(out, "%d\n", upvote)
	}
	out.Flush()

}

package main

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

func solve(r *bufio.Reader) {
	var n int
	fmt.Fscan(r, &n)
	total := 0
	var tmp int
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &tmp)
		if tmp != 2 {
			total++
		}
	}
	fmt.Println(total)
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

 package main

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

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

     defer out.Flush()

     var T, n, a int
     fmt.Fscan(in, &T)
     for ; T > 0; T-- {
         fmt.Fscan(in, &n)
         var ans int
         for i := 0; i < n; i++ {
             fmt.Fscan(in, &a)
             if (a & 1) == 1 {
                 ans++
             }
         }
         fmt.Fprintln(out, ans)
     }
     return
 }

package main

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

type CF1511A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1511A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1511A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1511A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1511A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1511A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1511A
Date: 21/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1511/A
Problem: CF1511A
**/
func (in *CF1511A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		s1 := 0
		s2 := 0
		for i := 0; i < n; i++ {
			tp := in.NextInt()
			if tp == 1 {
				s1++
			} else if tp == 2 {
				s2--
			} else {
				if s1 >= 0 {
					s1++
				} else {
					s2--
				}
			}
		}

		ans := 0
		if s1 > 0 {
			ans += s1
		}
		if s2 > 0 {
			ans += s2
		}
		fmt.Println(ans)

	}
}

func NewCF1511A(r *bufio.Reader) *CF1511A {
	return &CF1511A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1511A(bufio.NewReader(os.Stdin)).Run()
}

package main
import (
    "os"
    "fmt"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    fmt.Fscan(rd, &q)
    for t := 0; t < q; t++ {
        n := 0
        fmt.Fscan(rd, &n)
        a := make([]int, n)
        for i := range a {
            fmt.Fscan(rd, &a[i])
        }
        res := 0
        for _, v := range a {
            if v != 2 {
                res++
            }
        }
        fmt.Println(res)
    }
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		counter:=0
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if x == 1 || x==3 {
				counter++
			}
		}
		fmt.Fprintln(out,counter)
	}
}

package main

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

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

func solve(n int, r []int) int {
	var c int
	for _, x := range r {
		if x != 2 {
			c++
		}
	}
	return c
}

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

package main

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

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

	solve := func() {
		var n int
		ans := 0
		fmt.Fscan(in, &n)
		for i := 0; i < n; i++ {
			var x int
			fmt.Fscan(in, &x)
			if x != 2 {
				ans++
			}
		}
		fmt.Fprintln(out, ans)
	}

	T := 1
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		upvotes := 0

		for i := 0; i < n; i++ {
			r := ScanInt()

			if r != 2 {
				upvotes++
			}
		}

		fmt.Println(upvotes)
	}
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) Next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) NextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt()
	}
	return res
}
func (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	return res
}
func Min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func Max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

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

	TC := sc.NextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.NextInt()
		up := 0
		for i := 0; i < N; i++ {
			reviewerType := sc.NextInt()
			if reviewerType != 2 {
				up++
			}
		}
		fmt.Fprintln(wr, up)
	}

}

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

func readIntFromLine(s string) int64 {
        if v, err := strconv.ParseInt(s, 10, 64); err == nil {
                return v
        }
        return 0
}

func readIntsFromLine(s string) []int64 {
        nums := strings.Split(s, " ")
        var o []int64
        for _, n := range nums {
                o = append(o, readIntFromLine(n))
        }
        return o
}

func main() {
        s := bufio.NewScanner(os.Stdin)
        for s.Scan() {
                numTc := readIntFromLine(s.Text())
                for i := int64(0); i < numTc; i++ {
                        s.Scan()
                        //viewers := readIntFromLine(s.Text())
                        s.Scan()
                        reviews := readIntsFromLine(s.Text())
                        up, down := 0, 0
                        for _, r := range reviews {
                                if r == 2 {
                                        down++
                                } else {
                                        up++
                                }

                        }
                        fmt.Println(up)
                }
        }

/*
        var numTc int
        fmt.Scanf("%d", &numTc)
        for i  := 0; i < numTc; i++ {
                up, down, viewers := 0, 0, 0
                fmt.Scanf("%d", &viewers)
                for j := 0; j < viewers; j++ {
                        vType := 0
                        fmt.Scanf("%d", &vType)
                        switch  vType {
                                case 1:
                                        up++
                                case 2:
                                        down++
                                default:
                                        up++
                        }
                }
                fmt.Sprintf("%d", up)

        }
        */
}

package main

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

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

func main() {
	defer out.Flush()

	var t int
	Fscan(in, &t)

	for cases := 0; cases < t; cases++ {
		var n, answer int
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			var temp int
			Fscan(in, &temp)
			if temp == 1 || temp == 3 {
				answer++
			}
		}

		Fprintln(out, answer)
	}
}

package main

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

var io *IO

type IO struct {
	*bufio.ReadWriter
}

func init() {
	io = &IO{irw()}
}

func irw(size ...int) *bufio.ReadWriter {
	if len(size) == 0 {
		return bufio.NewReadWriter(ir(), iw())
	}
	return bufio.NewReadWriter(ir(size[0]), iw(size[1]))
}

func ir(size ...int) *bufio.Reader {
	if len(size) == 0 {
		return bufio.NewReader(os.Stdin)
	}
	return bufio.NewReaderSize(os.Stdin, size[0])
}

func iw(size ...int) *bufio.Writer {
	if len(size) == 0 {
		return bufio.NewWriter(os.Stdout)
	}
	return bufio.NewWriterSize(os.Stdin, size[0])
}

func main() {
	T := rI()
	for t := 0; t < T; t++ {
		n := rI()
		ns := ris()
		cnt := 0
		for i := 0; i < n; i++ {
			if ns[i] == 2 {
				cnt++
			}
		}
		fmt.Println(n - cnt)
	}
}

func rl() string {
	l, _, _ := io.ReadLine()
	return string(l)
}

func ri() int64 {
	s := rl()
	i64, _ := strconv.ParseInt(s, 10, 64)
	return i64
}

func rI() int {
	return int(ri())
}

func ris(sep ...string) []int64 {
	s := rl()
	var splits []string
	if sep == nil {
		splits = strings.Split(s, " ")
	} else {
		splits = strings.Split(s, sep[0])
	}
	ns := make([]int64, len(splits))
	for i, split := range splits {
		i64, _ := strconv.ParseInt(split, 10, 64)
		ns[i] = i64
	}
	return ns
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) {
		var n,c int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			if a[i] != 2 {
				c++
			}
		}
		Fprintln(out, c)
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

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

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

	for case_idx := 0; case_idx < t; case_idx++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		upvote := 0
		var rType int
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &rType)
			if rType == 1 || rType == 3 {
				upvote++
			}
		}
		fmt.Fprintf(out, "%d\n", upvote)
	}

}

package main

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

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

	for case_idx := 0; case_idx < t; case_idx++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		upvote := 0
		var rType int
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &rType)
			if rType == 1 || rType == 3 {
				upvote++
			}
		}
		fmt.Fscanf(in, "\n")
		fmt.Fprintf(out, "%d\n", upvote)
	}

}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for case_idx := 0; case_idx < t; case_idx++ {
		var n int
		fmt.Scanf("%d\n", &n)
		upvote := 0
		var rType int
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &rType)
			if rType == 1 || rType == 3 {
				upvote++
			}
		}
		fmt.Printf("%d\n", upvote)
	}

}

package main

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

func solve(r *bufio.Reader) {
	var n int
	fmt.Fscan(r, &n)
	total := 0
	var tmp int
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &tmp)
		if tmp == 1 || ((total != 0 || i == 0) && tmp == 3) {
			total++
		}
	}
	fmt.Println(total)
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

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

func solve(r *bufio.Reader) {
	var n int
	fmt.Fscan(r, &n)
	total := 0
	var tmp int
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &tmp)
		if tmp != 2 && total != 0 {
			total++
		}
	}
	fmt.Println(total)
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

 package main

 import "fmt"

 func main() {
     var T, n, a int
     fmt.Scanf("%d", &T)
     for ; T > 0; T-- {
         fmt.Scanf("%d", &n)
         var ans int
         for i := 0; i < n; i++ {
             fmt.Scan(&a)
             if (a & 1) == 1 {
                 ans++
             }
         }
         fmt.Println(ans)
     }
     return
 }

 package main

 import "fmt"

 func main() {
     var T, n, a int
     fmt.Scanf("%d", &T)
     for ; T > 0; T-- {
         fmt.Scanf("%d", &n)
         var ans int
         for i := 0; i < n; i++ {
             fmt.Scanf("%d", &a)
             if (a & 1) == 1 {
                 ans++
             }
         }
         fmt.Println(ans)
     }
     return
 }

package main

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

type CF1511A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1511A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1511A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1511A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1511A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1511A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1511A
Date: 21/11/21
User: epradere
URL: https://codeforces.com/problemset/problem/1511/A
Problem: CF1511A
**/
func (in *CF1511A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		s1 := 0
		s2 := 0
		for i := 0; i < n; i++ {
			tp := in.NextInt()
			if tp == 1 {
				if s1 < s2 {
					s1++
				} else {
					s2++
				}
			} else if tp == 2 {
				if s1 < s2 {
					s1--
				} else {
					s2--
				}
			} else {
				if s1 >= 0 {
					s1++
				} else if s2 >= 0 {
					s2++
				} else if s1 > s2 {
					s1--
				} else {
					s2--
				}
			}
		}

		ans := 0
		if s1 > 0 {
			ans += s1
		}
		if s2 > 0 {
			ans += s2
		}
		fmt.Println(ans)

	}
}

func NewCF1511A(r *bufio.Reader) *CF1511A {
	return &CF1511A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1511A(bufio.NewReader(os.Stdin)).Run()
}


// Author: sighduck
// URL: https://codeforces.com/contest/1196/problem/C

package main

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

const (
	MinValue = -100000
	MaxValue = 100000
)

type Robot struct {
	X int
	Y int
	L int
	U int
	R int
	D int
}

type Solution struct {
	Exists bool
	X      int
	Y      int
}

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

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

func Solve(n int, robots []Robot) Solution {
	xmin, xmax, ymin, ymax := MinValue, MaxValue, MinValue, MaxValue
	for _, robot := range robots {
		if robot.R == 0 {
			xmax = min(xmax, robot.X)
		}
		if robot.L == 0 {
			xmin = max(xmin, robot.X)
		}
		if robot.U == 0 {
			ymax = min(ymax, robot.Y)
		}
		if robot.D == 0 {
			ymin = max(ymin, robot.Y)
		}
	}
	if xmin > xmax || ymin > ymax {
		return Solution{Exists: false}
	}
	return Solution{Exists: true, X: xmin, Y: ymin}
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		robots := make([]Robot, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(
				reader,
				"%d %d %d %d %d %d\n",
				&robots[i].X, &robots[i].Y, &robots[i].L, &robots[i].U, &robots[i].R, &robots[i].D,
			)
		}
		solution := Solve(n, robots)
		if solution.Exists {
			fmt.Fprintf(writer, "1 %d %d\n", solution.X, solution.Y)
		} else {
			fmt.Fprintf(writer, "0\n")
		}
	}
}

package main

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

func main() {

	//stdin, err := os.Open("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

	var q int
	fmt.Fscanf(reader, "%d\n", &q)

	for i := 0; i < q; i++ {
		var n, minx, miny, maxx, maxy int = 0, -1e5, -1e5, 1e5, 1e5
		fmt.Fscanf(reader, "%d\n", &n)
		for j := 0; j < n; j++ {
			var x, y, f1, f2, f3, f4 int
			fmt.Fscanf(reader, "%d %d %d %d %d %d\n", &x, &y, &f1, &f2, &f3, &f4)
			// !left
			if f1 == 0 {
				minx = int(math.Max(float64(minx), float64(x)))
			}
			// !top
			if f2 == 0 {
				maxy = int(math.Min(float64(maxy), float64(y)))
			}
			// !right
			if f3 == 0 {
				maxx = int(math.Min(float64(maxx), float64(x)))
			}
			// !down
			if f4 == 0 {
				miny = int(math.Max(float64(miny), float64(y)))
			}

		}
		if minx > maxx || miny > maxy {
			fmt.Fprintf(writer, "0\n")
		} else {
			fmt.Fprintf(writer, "1 %d %d\n", minx, miny)
		}
	}

	writer.Flush()
}

package main

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

/* solution */

func solve() {
	q := readInt()
	for i := 0; i < q; i++ {
		solveOne()
	}
}

func solveOne() {

	n := readInt()

	l, r, t, b := -100000, 100000, 100000, -100000
	for i := 0; i < n; i++ {
		x, y, ml, mt, mr, mb := readInt(), readInt(), readInt(), readInt(), readInt(), readInt()
		if ml == 0 && l < x {
			l = x
		}
		if mr == 0 && x < r {
			r = x
		}
		if mt == 0 && y < t {
			t = y
		}
		if mb == 0 && b < y {
			b = y
		}
	}
	if l <= r && b <= t {
		printInt(1)
		printInt(l)
		printInt(t)
		println()
	} else {
		printInt(0)
		println()
	}

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

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

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString(" ")
}

func println() {
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

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

	var q int
	fmt.Fscanf(input, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		fmt.Fscanf(input, "%d\n", &n)

		xMax := 100000
		xMin := -100000
		yMax := 100000
		yMin := -100000
		for j := 0; j < n; j++ {
			var x, y int
			f := make([]int, 4)
			fmt.Fscanf(input, "%d %d %d %d %d %d\n", &x, &y, &f[0], &f[1], &f[2], &f[3])

			if f[0] == 0 && x > xMin {
				xMin = x
			}
			if f[1] == 0 && y < yMax {
				yMax = y
			}
			if f[2] == 0 && x < xMax {
				xMax = x
			}
			if f[3] == 0 && y > yMin {
				yMin = y
			}
		}
		if xMax < xMin || yMax < yMin {
			fmt.Printf("0\n")
		} else {
			fmt.Printf("1 %d %d\n", xMin, yMin)
		}
	}
}

package main

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

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

	var q int
	fmt.Fscanf(input, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		fmt.Fscanf(input, "%d\n", &n)

		xMax := math.MinInt32
		xMin := math.MaxInt32
		yMax := math.MinInt32
		yMin := math.MaxInt32
		for j := 0; j < n; j++ {
			var x, y int
			f := make([]int, 4)
			fmt.Fscanf(input, "%d %d %d %d %d %d\n", &x, &y, &f[0], &f[1], &f[2], &f[3])

			if f[0] == 0 && xMin > x {
				xMin = x
			}
			if f[1] == 0 && yMax < y {
				yMax = y
			}
			if f[2] == 0 && xMax < x {
				xMax = x
			}
			if f[3] == 0 && yMin > y {
				yMin = y
			}
		}
		if xMax == math.MinInt32 {
			xMax = 100000
		}
		if xMin == math.MaxInt32 {
			xMin = -100000
		}
		if yMax == math.MinInt32 {
			yMax = 100000
		}
		if yMin == math.MaxInt32 {
			yMin = -100000
		}
		if xMax < xMin || yMax < yMin {
			fmt.Printf("0\n")
		} else {
			fmt.Printf("1 %d %d\n", xMin, yMin)
		}
	}
}


package main

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

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

const mod = 998244353

// 1 2 3 4
func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n, c int
		fmt.Fscan(in, &n, &c)
		nums := make([]int, c+1)

		for i := 0; i < n; i++ {
			num := 0
			fmt.Fscan(in, &num)
			nums[num] = 1
		}
		for i := 1; i < len(nums); i++ {
			nums[i] = nums[i] + nums[i-1]
		}
		ok := true
	out:
		for i := 2; i <= c; i++ {
			if nums[i]-nums[i-1] == 0 {
				continue
			}
			for j := i; j <= c; j += i {
				max := j + i - 1
				if max > c {
					max = c
				}
				if nums[max]-nums[j-1] > 0 && nums[j/i]-nums[j/i-1] == 0 {
					ok = false
					break out
				}
			}
		}
		if ok {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

var T int

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

	Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n, c int
		Fscan(in, &n, &c)
		a := make([]int, n+1)
		cnt := make([]int, 2*c+1)
		pre := make([]int, 2*c+1)
		for j := 1; j <= n; j++ {
			Fscan(in, &a[j])
			cnt[a[j]]++
		}

		for i := 1; i <= 2*c; i++ {
			pre[i] += pre[i-1] + cnt[i]
		}

		ok := true
		for i := 1; i <= c; i++ {
			if cnt[i] > 0 {
				for j := 1; i*j <= c; j++ {
					if cnt[j] == 0 && pre[i*j-1] != pre[i*(j+1)-1] {
						ok = false
						break
					}
				}
				if !ok {
					break
				}
			}
		}
		if ok {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}


package main

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

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

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

func main() {
	defer out.Flush()
	inn := bufio.NewScanner(os.Stdin)
	inn.Split(bufio.ScanWords)
	r := func() (x int) {
		inn.Scan()
		data := inn.Bytes()
		f := 1
		if data[0] == '-' {
			f = -1
			data = data[1:]
		}
		for _, b := range data {
			x = x*10 + int(b&15)
		}
		return f * x
	}
	var n int
	n = r()
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = int64(r())
	}
	for i := 1; i < n; i++ {
		a[i] += a[i-1]
	}
	if a[n-1] == 1 {
		Fprint(out, -1)
		return
	}
	var ans = int64(1e18)
	tmp := a[n-1]
	cal := func(x int64) int64 {
		var res int64 = 0
		for i := 0; i < n; i++ {
			res += min(a[i]%x, x-a[i]%x)
		}
		return res
	}
	for f := int64(2); f <= int64(math.Sqrt(float64(tmp)))+1; f++ {
		if tmp%f == 0 {
			ans = min(ans, cal(int64(f)))
			for tmp%f == 0 {
				tmp /= f
			}
		}
	}
	if tmp > 1 {
		ans = min(ans, cal(tmp))
	}
	Fprint(out, ans)
}

package main

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

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

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

func main() {
	defer out.Flush()
	inn := bufio.NewScanner(os.Stdin)
	inn.Split(bufio.ScanWords)
	r := func() (x int) {
		inn.Scan()
		data := inn.Bytes()
		if data[0] == '-' {
			for _, b := range data[1:] {
				x = x*10 + int(b&15)
			}
			return -x
		}
		for _, b := range data {
			x = x*10 + int(b&15)
		}
		return
	}
	var n int
	n = r()
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = int64(r())
	}
	for i := 1; i < n; i++ {
		a[i] += a[i-1]
	}
	if a[n-1] == 1 {
		Fprint(out, -1)
		return
	}
	var ans = int64(1e18)
	tmp := a[n-1]
	cal := func(x int64) int64 {
		var res int64 = 0
		for i := 0; i < n; i++ {
			res += min(a[i]%x, x-a[i]%x)
		}
		return res
	}
	for f := int64(2); f <= int64(math.Sqrt(float64(tmp)))+1; f++ {
		if tmp%f == 0 {
			ans = min(ans, cal(int64(f)))
			for tmp%f == 0 {
				tmp /= f
			}
		}
	}
	if tmp > 1 {
		ans = min(ans, cal(tmp))
	}
	Fprint(out, ans)
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Buffer([]byte{}, 1000000)
	inn.Split(bufio.ScanWords)
	n := rd()
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = rdll()
	}
	for i := 1; i < n; i++ {
		a[i] += a[i-1]
	}
	if a[n-1] == 1 {
		Fprint(out, -1)
		return
	}
	var ans = int64(1e18)
	tmp := a[n-1]
	cal := func(x int64) int64 {
		var res int64 = 0
		for i := 0; i < n; i++ {
			res += min(a[i]%x, x-a[i]%x)
		}
		return res
	}
	for f := int64(2); f*f <= tmp; f++ {
		if tmp%f == 0 {
			ans = min(ans, cal(int64(f)))
			for tmp%f == 0 {
				tmp /= f
			}
		}
	}
	if tmp > 1 {
		ans = min(ans, cal(tmp))
	}
	Fprint(out, ans)
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.Atoi(string(data))
	return x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.ParseInt(string(data), 10, 0)
	return x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1254B2(_r io.Reader, out io.Writer) {
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}
	n := r()
	sum := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		sum[i] = sum[i-1] + int64(r())
	}
	x := sum[n]
	if x < 2 {
		Fprint(out, -1)
		return
	}
	a := []int64{}
	for i := int64(2); i*i <= x; i++ {
		k := 0
		for ; x%i == 0; x /= i {
			k++
		}
		if k > 0 {
			a = append(a, i)
		}
	}
	if x > 1 {
		a = append(a, x)
	}
	ans := int64(1e18)
	for _, p := range a {
		s := int64(0)
		for _, v := range sum {
			s += min(v%p, p-v%p)
		}
		ans = min(ans, s)
	}
	Fprint(out, ans)
}

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

package main

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

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	n := rd()
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = rdll()
	}
	for i := 1; i < n; i++ {
		a[i] += a[i-1]
	}
	if a[n-1] == 1 {
		Fprint(out, -1)
		return
	}
	var ans = int64(1e18)
	tmp := a[n-1]
	cal := func(x int64) int64 {
		var res int64 = 0
		for i := 0; i < n; i++ {
			res += min(a[i]%x, x-a[i]%x)
		}
		return res
	}
	for f := int64(2); f <= int64(math.Sqrt(float64(tmp)))+1; f++ {
		if tmp%f == 0 {
			ans = min(ans, cal(int64(f)))
			for tmp%f == 0 {
				tmp /= f
			}
		}
	}
	if tmp > 1 {
		ans = min(ans, cal(tmp))
	}
	Fprint(out, ans)
}

func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1254B2(_r io.Reader, out io.Writer) {
	_i, buf := 1<<12, make([]byte, 1<<12)
	rc := func() byte {
		if _i == 1<<12 {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}
	n := r()
	sum := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		sum[i] = sum[i-1] + int64(r())
	}
	x := sum[n]
	if x < 2 {
		Fprint(out, -1)
		return
	}
	a := []int64{}
	for i := int64(2); i*i <= x; i++ {
		k := 0
		for ; x%i == 0; x /= i {
			k++
		}
		if k > 0 {
			a = append(a, i)
		}
	}
	if n > 1 {
		a = append(a, x)
	}
	ans := int64(1e18)
	for _, p := range a {
		s := int64(0)
		for _, v := range sum {
			s += min(v%p, p-v%p)
		}
		ans = min(ans, s)
	}
	Fprint(out, ans)
}

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

package main

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

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	n := rd()
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = rdll()
	}
	for i := 1; i < n; i++ {
		a[i] += a[i-1]
	}
	if a[n-1] == 1 {
		Fprint(out, -1)
		return
	}
	var ans = int64(1e18)
	tmp := a[n-1]
	cal := func(x int64) int64 {
		var res int64 = 0
		for i := 0; i < n; i++ {
			res += min(a[i]%x, x-a[i]%x)
		}
		return res
	}
	for f := int64(2); f <= int64(math.Sqrt(float64(tmp)))+1; f++ {
		if tmp%f == 0 {
			ans = min(ans, cal(int64(f)))
			for tmp%f == 0 {
				tmp /= f
			}
		}
	}
	if tmp > 1 {
		ans = min(ans, cal(tmp))
	}
	Fprint(out, ans)
}

func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(-1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}