$n$ robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental, and their behavior is not tested yet, so they may be really dangerous!

Fortunately, even though your robots have escaped, you still have some control over them. First of all, you know the location of each robot: the world you live in can be modeled as an infinite coordinate plane, and the $i$-th robot is currently located at the point having coordinates ($x_i$, $y_i$). Furthermore, you may send exactly one command to all of the robots. The command should contain two integer numbers $X$ and $Y$, and when each robot receives this command, it starts moving towards the point having coordinates ($X$, $Y$). The robot stops its movement in two cases:  either it reaches ($X$, $Y$);  or it cannot get any closer to ($X$, $Y$). 

Normally, all robots should be able to get from any point of the coordinate plane to any other point. Each robot usually can perform four actions to move. Let's denote the current coordinates of the robot as ($x_c$, $y_c$). Then the movement system allows it to move to any of the four adjacent points:  the first action allows it to move from ($x_c$, $y_c$) to ($x_c - 1$, $y_c$);  the second action allows it to move from ($x_c$, $y_c$) to ($x_c$, $y_c + 1$);  the third action allows it to move from ($x_c$, $y_c$) to ($x_c + 1$, $y_c$);  the fourth action allows it to move from ($x_c$, $y_c$) to ($x_c$, $y_c - 1$). 

Unfortunately, it seems that some movement systems of some robots are malfunctioning. For each robot you know which actions it can perform, and which it cannot perform.

You want to send a command so all robots gather at the same point. To do so, you have to choose a pair of integer numbers $X$ and $Y$ so that each robot can reach the point ($X$, $Y$). Is it possible to find such a point?


-----Input-----

The first line contains one integer $q$ ($1 \le q \le 10^5$) — the number of queries.

Then $q$ queries follow. Each query begins with one line containing one integer $n$ ($1 \le n \le 10^5$) — the number of robots in the query. Then $n$ lines follow, the $i$-th of these lines describes the $i$-th robot in the current query: it contains six integer numbers $x_i$, $y_i$, $f_{i, 1}$, $f_{i, 2}$, $f_{i, 3}$ and $f_{i, 4}$ ($-10^5 \le x_i, y_i \le 10^5$, $0 \le f_{i, j} \le 1$). The first two numbers describe the initial location of the $i$-th robot, and the following four numbers describe which actions the $i$-th robot can use to move ($f_{i, j} = 1$ if the $i$-th robot can use the $j$-th action, and $f_{i, j} = 0$ if it cannot use the $j$-th action).

It is guaranteed that the total number of robots over all queries does not exceed $10^5$.


-----Output-----

You should answer each query independently, in the order these queries appear in the input.

To answer a query, you should do one of the following:  if it is impossible to find a point that is reachable by all $n$ robots, print one number $0$ on a separate line;  if it is possible to find a point that is reachable by all $n$ robots, print three space-separated integers on the same line: $1$ $X$ $Y$, where $X$ and $Y$ are the coordinates of the point reachable by all $n$ robots. Both $X$ and $Y$ should not exceed $10^5$ by absolute value; it is guaranteed that if there exists at least one point reachable by all robots, then at least one of such points has both coordinates not exceeding $10^5$ by absolute value.


-----Example-----
Input
4
2
-1 -2 0 0 0 0
-1 -2 0 0 0 0
3
1 5 1 1 1 1
2 5 0 1 0 1
3 5 1 0 0 0
2
1337 1337 0 1 1 1
1336 1337 1 1 0 1
1
3 5 1 1 1 1

Output
1 -1 -2
1 2 5
0
1 -100000 -100000

Difficulty: introductory

Starter code:

Solutions:
def main():
    import sys
    input = sys.stdin.readline
    
    def solve():
        n = int(input())
        maxx = 10**5
        minx = -10**5
        maxy = 10**5
        miny = -10**5
        
        for _ in range(n):
            x, y, f1, f2, f3, f4 = map(int, input().split())
            if not f1:
                minx = max(minx, x)
            if not f2:
                maxy = min(maxy, y)
            if not f3:
                maxx = min(maxx, x)
            if not f4:
                miny = max(miny, y)
        
        if minx > maxx or miny > maxy:
            print(0)
        else:
            print(1, minx, miny)
        
    
    for _ in range(int(input())):
        solve()
    
    return 0

main()

import sys
input = sys.stdin.readline

q=int(input())

for testcases in range(q):
    n=int(input())
    ROBOT=[list(map(int,input().split())) for i in range(n)]

    XMAX=10**5
    XMIN=-10**5
    YMAX=10**5
    YMIN=-10**5

    for x,y,a,b,c,d in ROBOT:
        if a==0:
            XMIN=max(XMIN,x)
        if b==0:
            YMAX=min(YMAX,y)
        if c==0:
            XMAX=min(XMAX,x)
        if d==0:
            YMIN=max(YMIN,y)

    #print(XMIN,XMAX,YMIN,YMAX)

    if XMIN>XMAX or YMIN>YMAX:
        print(0)
    else:
        print(1,XMIN,YMIN)

    


y = 10**5
T = int(input())
for _ in range(T):
  x = [-y, -y, y, y]
  n = int(input())
  for _ in range(n):
    a = list(map(int, input().split()))
    if not a[2]:
      x[0] = max(x[0], a[0])
    if not a[3]:
      x[3] = min(x[3], a[1])
    if not a[4]:
      x[2] = min(x[2], a[0])
    if not a[5]:
      x[1] = max(x[1], a[1])
  if x[0] <= x[2] and x[1] <= x[3]:
    print(1, x[0], x[1])
  else:  
    print(0)
  


q = int(input())
for _ in range(q):
    n = int(input())
    lm = dm = -100000
    rm = um = 100000
    for _ in range(n):
        x, y, l, u, r, d = list(map(int, input().split()))
        if l == 0:
            lm = max(lm, x)
        if r == 0:
            rm = min(rm, x)
        if u == 0:
            um = min(um, y)
        if d == 0:
            dm = max(dm, y)
    if lm > rm or um < dm:
        print(0)
    else:
        print(1, lm, dm)



import sys
input = sys.stdin.readline

Q = int(input())
for _ in range(Q):
    N = int(input())
    minx, miny, maxx, maxy = -10**5, -10**5, 10**5, 10**5
    for __ in range(N):
        X, Y, L, U, R, D = list(map(int, input().split()))
        if L == 0:
            minx = max(minx, X)
        if R == 0:
            maxx = min(maxx, X)
        if U == 0:
            maxy = min(maxy, Y)
        if D == 0:
            miny = max(miny, Y)
    if maxx >= minx and maxy >= miny:
        print(1, minx, miny)
    else:
        print(0)




from sys import stdin
c=int(stdin.readline().strip())
for cas in range(c):
    n=int(stdin.readline().strip())
    s=[list(map(int,stdin.readline().strip().split())) for i in range(n)]
    mn=-10**5
    interval=[[mn,-mn],[mn,-mn]]
    flag=True
    for i in s:
        if i[2]==0:
            if (interval[0][1]<i[0]):
                flag=False
                break
            else:
                interval[0][0]=max(i[0],interval[0][0])
        if i[3]==0:
            if( interval[1][0]>i[1]):
                flag=False
                break
            else:
                interval[1][1]=min(interval[1][1],i[1])
        if i[4]==0:
            if interval[0][0]>i[0]:
                flag=False
                break
            else:
                interval[0][1]=min(interval[0][1],i[0])
        if i[5]==0:
            if interval[1][1]<i[1]:
                flag=False
                break
            else:
                interval[1][0]=max(interval[1][0],i[1])
                

    if flag:
        print(1,interval[0][0],interval[1][0])
    else:
        print(0)
    
            
            


for _ in range(int(input())):
    n = int(input())
    maxx, minx = 100000, -100000
    maxy, miny = 100000, -100000
    for _ in range(n):
        xi, yi, d, r, u, l = tuple(map(int, input().split()))
        if d == 0:
            minx = xi if xi > minx else minx
        if r == 0:
            maxy = yi if yi < maxy else maxy
        if u == 0:
            maxx = xi if xi < maxx else maxx
        if l == 0:
            miny = yi if yi > miny else miny
    if miny <= maxy and minx <= maxx:
        print(1, minx, miny)
    else:
        print(0)

import sys
 
t = int(input())
for _ in range(t):
    n = int(sys.stdin.readline())
    xMin, xMax, yMin, yMax = -100000, 100000, -100000, 100000
    x, y = 0, 0
    res = 1
    for i in range(n):
        xi, yi, xMinus, yPlus, xPlus, yMinus = list(map(int, sys.stdin.readline().split()))
        if xMinus == 0:
            xMin = max(xi, xMin)
        if xPlus == 0:
            xMax = min(xi, xMax)
        if yMinus == 0:
            yMin = max(yi, yMin)
        if yPlus == 0:
            yMax = min(yi, yMax)
    if xMin<=xMax and yMin <= yMax:
        print(1, xMin, yMin)
    else:
        print(0)
 
 
 
## (x−1, y)
## (x, y+1)
## (x+1, y)
## (x, y−1)


def main():
    q = int(input())
    for i in range(q):
        n = int(input())
        l_x = -10 ** 5
        r_x = 10 ** 5
        l_y = -10 ** 5
        r_y = 10 ** 5
        flag = True
        for i in range(n):
            x, y, f1, f2, f3, f4 = map(int, input().split())
            if flag:
                if f1 == f3 == 0:
                    if not(x >= l_x and x <= r_x):
                        flag = False
                    else:
                        l_x = x
                        r_x = x
                elif f1 == 1 and f3 == 0:
                    r_x = min(x, r_x)
                elif f1 == 0 and f3 == 1:
                    l_x = max(x, l_x)
                if f2 == f4 == 0:
                    if not(y >= l_y and y <= r_y):
                        flag = False
                    else:
                        l_y = y
                        r_y = y
                elif f2 == 1 and f4 == 0:
                    l_y = max(y, l_y)
                elif f2 == 0 and f4 == 1:
                    r_y = min(y, r_y)
                if l_x > r_x or l_y > r_y:
                    flag = False
        if flag:
            print(1, l_x, l_y)
        else:
            print(0)

main()

import math
import sys

n = int(sys.stdin.readline().strip())
for i in range(n):
	n = int(sys.stdin.readline().strip())
	mx = -math.inf
	px = math.inf
	my = -math.inf
	py = math.inf
	# x, y, mx, py, px, my
	robots = [list(map(int, sys.stdin.readline().split())) for x in range(n)]
	for robot in robots:
		if robot[2] == 0:
			mx = max(robot[0], mx)

		if robot[5] == 0:
			my = max(robot[1], my)

		if robot[4] == 0:
			px = min(robot[0], px)

		if robot[3] == 0:
			py = min(robot[1], py)
	if mx > px or my > py:
		print(0)
	else:
		print(1, max(-100000, mx), max(-100000, my))


q = int(input())
for i in range(q):
    n = int(input())
    rowdown = -10 ** 5
    rowup = 10 ** 5
    colmnleft = -10 ** 5
    colmnright = 10 ** 5
    for j in range(n):
        x, y, left, up, right, down = list(map(int, input().split()))
        if not left:
            colmnleft = max(colmnleft, x)
        if not right:
            colmnright = min(colmnright, x)
        if not up:
            rowup = min(rowup, y)
        if not down:
            rowdown = max(rowdown, y)
    if rowdown > rowup or colmnleft > colmnright:
        print(0)
    else:
        print(1, colmnleft, rowdown)


import sys
input = lambda: sys.stdin.readline().strip()

T = int(input())
for _ in range(T):
    n = int(input())
    minx = -(10**5)
    maxx = 10**5
    miny = -(10**5)
    maxy = 10**5
    for i in range(n):
        x, y, f1, f2, f3, f4 = list(map(int, input().split()))
        if f1==0: minx = max(minx, x)
        if f2==0: maxy = min(maxy, y)
        if f3==0: maxx = min(maxx, x)
        if f4==0: miny = max(miny, y)
    if minx>maxx or miny>maxy: print(0)
    else:
        print(1, minx, miny)


from sys import stdin
from math import inf

q = int(stdin.readline())

class Rect:
    def __init__(self, x1 = -inf, y1 = -inf, x2 = inf, y2 = inf):
        if x1 > x2:
            x1, x2 = x2, x1
        if y1 > y2:
            y1, y2 = y2, y1

        self.x1 = x1
        self.y1 = y1
        self.x2 = x2
        self.y2 = y2

    def __str__(self):
        return "(%f, %f, %f, %f)" % (self.x1, self.y1, self.x2, self.y2)

def intersect(r1, r2):
    if r1 is None or r2 is None:
        return None
    if r1.x2 < r2.x1 or r2.x2 < r1.x1:
        return None
    if r1.y2 < r2.y1 or r2.y2 < r1.y1:
        return None
    return Rect(max(r1.x1, r2.x1), max(r1.y1, r2.y1), min(r1.x2, r2.x2), min(r1.y2, r2.y2))

for i in range(q):
    n = int(stdin.readline())

    inter = Rect()
    for i in range(n):
        x, y, f1, f2, f3, f4 = list(map(int, stdin.readline().split()))
        curRect = Rect()
        if f1 == 0:
            curRect.x1 = x
        if f2 == 0:
            curRect.y2 = y
        if f3 == 0:
            curRect.x2 = x
        if f4 == 0:
            curRect.y1 = y
        inter = intersect(inter, curRect)
    if inter is None:
        print("0")
    else:
        print("1 %d %d" % (int(max(inter.x1, -10**5)), int(max(inter.y1, -10**5))))


inf = 100000
for q in range(int(input())):
    n = int(input())
    l,u,r,d = -inf,inf,inf,-inf
    for i in range(n):
        x,y,f1,f2,f3,f4 = list(map(int,input().split()))
        if f1 == 0:
            l = max(l,x)
        if f2 == 0:
            u = min(u,y)
        if f3 == 0:
            r = min(r,x)
        if f4 == 0:
            d = max(d,y)
    if d>u or l>r:
        print(0)
    else:
        print(1,l,d)





a = int(input())
for i in range(a):
    d = []
    b = int(input())
    for j in range(b):
        d.append(list(map(int,input().split())))
    mix = -100000
    miy = mix
    maxx = 100000
    maxy = maxx
    f = True
    for j in range(b):
        x = d[j][0]
        y = d[j][1]
        if d[j][2] == 0:
            if x > maxx:
                print(0)
                f = False
                break
            mix = max(mix, x)
        if d[j][3] == 0:
            if y < miy:
                print(0)
                f = False
                break
            maxy = min(maxy, y)
        if d[j][5] == 0:
            if y > maxy:
                print(0)
                f = False
                break
            miy = max(miy, y)
        if d[j][4] == 0:
            if x < mix:
                print(0)
                f = False
                break
            maxx = min(maxx, x)
    if f:
        print(1, mix, miy)


''' CODED WITH LOVE BY SATYAM KUMAR '''

from sys import stdin, stdout
import cProfile, math
from collections import Counter,defaultdict,deque
from bisect import bisect_left,bisect,bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) # max depth of recursion
threading.stack_size(2**27)  # new thread will get stack of such size
fac_warmup = False
printHeap = str()
memory_constrained = False
P = 10**9+7
import sys

class merge_find:
    def __init__(self,n):
        self.parent = list(range(n))
        self.size = [1]*n
        self.num_sets = n
        self.lista = [[_] for _ in range(n)]
    def find(self,a):
        to_update = []
        while a != self.parent[a]:
            to_update.append(a)
            a = self.parent[a]
        for b in to_update:
            self.parent[b] = a
        return self.parent[a]
    def merge(self,a,b):
        a = self.find(a)
        b = self.find(b)
        if a==b:
            return
        if self.size[a]<self.size[b]:
            a,b = b,a
        self.num_sets -= 1
        self.parent[b] = a
        self.size[a] += self.size[b]
        self.lista[a] += self.lista[b]
    def set_size(self, a):
        return self.size[self.find(a)]
    def __len__(self):
        return self.num_sets

def display(string_to_print):
    stdout.write(str(string_to_print) + "\n")

def primeFactors(n): #n**0.5 complex 
    factors = dict()
    for i in range(2,math.ceil(math.sqrt(n))+1):  
        while n % i== 0: 
            if i in factors:
                factors[i]+=1
            else: factors[i]=1
            n = n // i 
    if n>2:
        factors[n]=1
    return (factors)

def all_factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def fibonacci_modP(n,MOD):
    if n<2: return 1
    #print (n,MOD)
    return (cached_fn(fibonacci_modP, (n+1)//2, MOD)*cached_fn(fibonacci_modP, n//2, MOD) + cached_fn(fibonacci_modP, (n-1) // 2, MOD)*cached_fn(fibonacci_modP, (n-2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n , p): 
    if (p <= n): 
        return 0
    res = (p - 1) 
    for i in range (n + 1, p): 
        res = (res * cached_fn(InverseEuler,i, p)) % p 
    return res 

def binary(n,digits = 20):
    b = bin(n)[2:]
    b = '0'*(digits-len(b))+b
    return b

def isprime(n):
    """Returns True if n is prime."""
    if n < 4:
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    i = 5
    w = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += w
        w = 6 - w
    return True

def generate_primes(n):
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * 2, n+1, p): 
                prime[i] = False
        p += 1
    return prime

factorial_modP = []
def warm_up_fac(MOD):
    nonlocal factorial_modP,fac_warmup
    if fac_warmup: return
    factorial_modP= [1 for _ in range(fac_warmup_size+1)]
    for i in range(2,fac_warmup_size):
        factorial_modP[i]= (factorial_modP[i-1]*i) % MOD
    fac_warmup = True

def InverseEuler(n,MOD):
    return pow(n,MOD-2,MOD)

def nCr(n, r, MOD):
    nonlocal fac_warmup,factorial_modP
    if not fac_warmup:
        warm_up_fac(MOD)
        fac_warmup = True
    return (factorial_modP[n]*((pow(factorial_modP[r], MOD-2, MOD) * pow(factorial_modP[n-r], MOD-2, MOD)) % MOD)) % MOD

def test_print(*args):
    if testingMode:
        print(args)

def display_list(list1, sep=" "):
    stdout.write(sep.join(map(str, list1)) + "\n")

def display_2D_list(li):
    for i in li:
        print(i)
def prefix_sum(li):
    sm = 0
    res = []
    for i in li:
        sm+=i
        res.append(sm)
    return res

def get_int():
    return int(stdin.readline().strip())

def get_tuple():
    return map(int, stdin.readline().split())

def get_list():
    return list(map(int, stdin.readline().split()))
import heapq,itertools
pq = []                         # list of entries arranged in a heap
entry_finder = {}               # mapping of tasks to entries
REMOVED = '<removed-task>' 
def add_task(task, priority=0):
    'Add a new task or update the priority of an existing task'
    if task in entry_finder:
        remove_task(task)
    count = next(counter)
    entry = [priority, count, task]
    entry_finder[task] = entry
    heapq.heappush(pq, entry)

def remove_task(task):
    'Mark an existing task as REMOVED.  Raise KeyError if not found.'
    entry = entry_finder.pop(task)
    entry[-1] = REMOVED

def pop_task():
    'Remove and return the lowest priority task. Raise KeyError if empty.'
    while pq:
        priority, count, task = heapq.heappop(pq)
        if task is not REMOVED:
            del entry_finder[task]
            return task
    raise KeyError('pop from an empty priority queue')
memory = dict()
def clear_cache():
    nonlocal memory
    memory = dict()
def cached_fn(fn, *args):
    nonlocal memory
    if args in memory:
        return memory[args]
    else:
        result = fn(*args)
        memory[args] = result
        return result

def ncr (n,r):
    return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))
def binary_serach(i,li):
    #print("Search for ",i)
    fn = lambda x: li[x]-x//i
    x = -1
    b = len(li)
    while b>=1:
        #print(b,x)
        while b+x<len(li) and fn(b+x)>0: #Change this condition 2 to whatever you like
            x+=b
        b=b//2
    return x

# -------------------------------------------------------------- MAIN PROGRAM
TestCases = True
testingMode = False
fac_warmup_size = 10**5+100
optimiseForReccursion = False #Can not be used clubbed with TestCases # WHen using recursive functions, use Python 3
from math import factorial

def main():
    n = get_int()
    minx = -10**5
    maxx = 10**5
    miny = -10**5
    maxy = 10**5
    for _ in range(n):
        xi, yi, nx, py, px, ny = get_tuple()
        if (nx == 0):
            minx = max(minx, xi)
        if (ny == 0):
            miny = max(miny, yi)
        if (px == 0):
            maxx = min(maxx, xi)
        if (py == 0):
            maxy = min(maxy, yi)
    if (maxx-minx)>=0 and (maxy-miny)>=0:
        print(1,minx,miny)
    else:
        print(0)






# --------------------------------------------------------------------- END=


if TestCases: 
    for i in range(get_int()): 
        cProfile.run('main()') if testingMode else main() 
else: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()

q = int(input())
for _ in range(q):
    n = int(input())
    x = []
    y = []
    f = []
    for _ in range(n):
        temp = tuple(map(int,input().split()))
        x.append(temp[0])
        y.append(temp[1])
        f.append(temp[2:])
    x_min = y_min = -100000
    x_max = y_max = 100000
    for i in range(n):
        if f[i][0] == 0:x_min = max(x_min,x[i])
        if f[i][1] == 0:y_max = min(y_max,y[i])
        if f[i][2] == 0:x_max = min(x_max,x[i])
        if f[i][3] == 0:y_min = max(y_min,y[i])
    if x_max < x_min:
        print(0)
        continue
    elif y_max < y_min:
        print(0)
        continue
    else:
        print('1 %d %d' % (x_min,y_min))




q = int(input())
for i in range(q):
    n = int(input())
    l = -100000
    t = 100000
    r = 100000
    b = -100000
    for j in range(n):
        x, y, f1, f2, f3, f4 = list(map(int, input().split()))
        if f1 == 0:
            if l <= x:
                l = x
        if f2 == 0:
            if t >= y:
                t = y
        if f3 == 0:
            if r >= x:
                r = x
        if f4 == 0:
            if b <= y:
                b = y
    cx,cy=None,None
    ans = 1
    if l <= r:
        cx = l
    else:
        ans =0
    if b <= t:
        cy = b
    else:
        ans = 0
    if ans == 0:
        print(ans)
    else:
        print(ans, cx, cy)



inf=10**5
import sys
for _ in range(int(input())):
    n=int(sys.stdin.readline())
    a=[]
    for i in range(n):
        a.append(list(map(int,sys.stdin.readline().split())))
    xl=-inf
    xh=10**5
    yl=-inf
    yh=10**5
    for i in range(n):
        if a[i][2]==0:
            xl=max(xl,a[i][0])
        else:
            xl=max(xl,-inf)
        if a[i][3]==0:
            yh=min(yh,a[i][1])
        else:
            yh=min(yh,10**5)
            
        if a[i][4]==0:
            xh=min(xh,a[i][0])
        else:
            xh=min(xh,10**5)
        if a[i][5]==0:
            yl=max(yl,a[i][1])
        else:
            yl=max(yl,-inf)
            
        # print(xl,xh,yl,yh)        
    if xl<=xh and yl<=yh:
        print(1,xl,yl)
    else:
        print(0)