Chef is an advocate for Go Green Initiative. Today he had n trees planted in a row outside his his restaurant. Today, the height of i-th tree is hi feet. The trees grow at a rate of mi feet per day.
Chef knows that trees will look beautiful if they form a zig-zag sequence. The trees will be said to be in Zig-zag sequence if the heights of tree first increases or decreases, then alternates between decreasing/increasing respectively. Formally, the trees will be said to in Zig-zag sequence if one of the following two conditions holds.
- h1 < h2 > h3 < h4 and so on..
- h1 >  h2 < h3 > h4 and so on..
Chef wants to know intervals of time when the heights of the trees will form a zig-zag sequence.
-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer n, denoting the number of trees.
The ith of following N lines contains two space separated integers hi and mi, denoting the initial height and the growth speed for ith tree.
-----Output-----
For each test case, output an integer Q - the amount of the periods of consecutive moments of time, when the trees for a zig-zag sequence.
On the following Q lines, output the intervals of time when the trees' heights form a zig-zag sequence. For each intervals, output its' smallest and the largest instants of time. If the range is infinite, output Inf as the right bound.
The test cases are designed in such a way that the total output won't exceed 2 MB.
-----Constraints-----
- 1 ≤ T ≤ 105
- 1 ≤ n ≤ 10
- Subtask 1 (23 points): 0 ≤ hi, mi ≤ 10
- Subtask 2 (77 points): 0 ≤ hi, mi ≤ 109
- 1 ≤ sum of n over a test cases in a single test file ≤ 5 × 105
-----Example-----
Input:3
3
0 1
2 2
0 3
2
2 1
1 2
3
1 1
2 2
3 3
Output:1
0 1
2
0 0
2 Inf
0
-----Explanation-----
Example case 1. In the first case 0 2 0 is already a zig-zag sequence, but on the 2nd second it will become 2 6 6 and will never turn back into zig-zag
import math
def CHAHG1(xh,m):
 x = [x for x in xh]
 y = [y for y in m]
 
 up = []
 lw = []
 L = None
 R = None
 for i in range(0,len(x)-1):
  if(i%2==0):
   if((y[i]-y[i+1])==0):
    if(x[i] < x[i+1]):
     lw.append(0)
    else:
     return False
   else:
    if(y[i] < y[i+1]):
     l = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     l = int(math.floor(l))+1
     lw.append(max(0,l))
    else:
     r = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     r = int(math.ceil(r))-1
     if(r<0):
      return False
     up.append(r)
  else:
   if((y[i]-y[i+1])==0):
    if(x[i] > x[i+1]):
     lw.append(0)
    else:
     return False
   else:
    if(y[i] > y[i+1]):
     l = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     l = int(math.floor(l))+1
     lw.append(max(0,l))
    else:
     r = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     r = int(math.ceil(r))-1
     if(r<0):
      return False
     up.append(r)
 if(len(lw)>0):
  L = max(lw)
 else:
  L = 0
 if(len(up) > 0):
  R = min(up)
  if(L>R):
   return False
 else:
  R = "Inf"
 
 return L,R
 
def CHAHG2(xh,m):
 x = [x for x in xh]
 y = [y for y in m]
 up = []
 lw = []
 L = None
 R = None
 for i in range(0,len(x)-1):
  if(i%2==1):
   if((y[i]-y[i+1])==0):
    if(x[i] < x[i+1]):
     lw.append(0)
    else:
     return False
   else:
    if(y[i] < y[i+1]):
     l = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     l = int(math.floor(l))+1
     lw.append(max(0,l))
    else:
     r = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     r = int(math.ceil(r))-1
     if(r<0):
      return False
     up.append(r)
  else:
   if((y[i]-y[i+1])==0):
    if(x[i] > x[i+1]):
     lw.append(0)
    else:
     return False
   else:
    if(y[i] > y[i+1]):
     l = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     l = int(math.floor(l))+1
     lw.append(max(0,l))
    else:
     r = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     r = int(math.ceil(r))-1
     if(r<0):
      return False
     up.append(r)
 if(len(lw)>0):
  L = max(lw)
 else:
  L = 0
 if(len(up) > 0):
  R = min(up)
  if(L>R):
   return False
 else:
  R = "Inf"
 
 return L,R
 
T = int(input())
while T:
 T = T-1
 N = int(input())
 xh = []
 m = []
 for i in range(N):
  a,b = list(map(int,input().split()))
  xh.append(a)
  m.append(b)
 
 res = []
 p = CHAHG1(xh,m)
 q = CHAHG2(xh,m)
 if(p is not False):
  res.append(p)
 if(q is not False):
  res.append(q)
  
 res.sort()
 sz = len(res)
 
 if(N==1):
  print("1")
  print("0 Inf")
 else:
  if(sz==2 and (res[0][1]+1 == res[1][0])):
   print("1")
   print(res[0][0],res[1][1])
  else:
   print(sz)
   for L,R in res:
    print(L,R)
 

import math
def CHAHG1(xh,m):
 x = [x for x in xh]
 y = [y for y in m]
 
 up = []
 lw = []
 L = None
 R = None
 for i in range(0,len(x)-1):
  if(i%2==0):
   if((y[i]-y[i+1])==0):
    if(x[i] < x[i+1]):
     lw.append(0)
    else:
     return False
   else:
    if(y[i] < y[i+1]):
     l = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     l = int(math.floor(l))+1
     lw.append(max(0,l))
    else:
     r = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     r = int(math.ceil(r))-1
     if(r<0):
      return False
     up.append(r)
  else:
   if((y[i]-y[i+1])==0):
    if(x[i] > x[i+1]):
     lw.append(0)
    else:
     return False
   else:
    if(y[i] > y[i+1]):
     l = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     l = int(math.floor(l))+1
     lw.append(max(0,l))
    else:
     r = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     r = int(math.ceil(r))-1
     if(r<0):
      return False
     up.append(r)
 if(len(lw)>0):
  L = max(lw)
 else:
  L = 0
 if(len(up) > 0):
  R = min(up)
  if(L>R):
   return False
 else:
  R = "Inf"
 
 return L,R
 
def CHAHG2(xh,m):
 x = [x for x in xh]
 y = [y for y in m]
 up = []
 lw = []
 L = None
 R = None
 for i in range(0,len(x)-1):
  if(i%2==1):
   if((y[i]-y[i+1])==0):
    if(x[i] < x[i+1]):
     lw.append(0)
    else:
     return False
   else:
    if(y[i] < y[i+1]):
     l = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     l = int(math.floor(l))+1
     lw.append(max(0,l))
    else:
     r = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     r = int(math.ceil(r))-1
     if(r<0):
      return False
     up.append(r)
  else:
   if((y[i]-y[i+1])==0):
    if(x[i] > x[i+1]):
     lw.append(0)
    else:
     return False
   else:
    if(y[i] > y[i+1]):
     l = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     l = int(math.floor(l))+1
     lw.append(max(0,l))
    else:
     r = (float)(x[i+1]-x[i])/(y[i]-y[i+1])
     r = int(math.ceil(r))-1
     if(r<0):
      return False
     up.append(r)
 if(len(lw)>0):
  L = max(lw)
 else:
  L = 0
 if(len(up) > 0):
  R = min(up)
  if(L>R):
   return False
 else:
  R = "Inf"
 
 return L,R
 
T = int(input())
while T:
 T = T-1
 N = int(input())
 xh = []
 m = []
 for i in range(N):
  a,b = list(map(int,input().split()))
  xh.append(a)
  m.append(b)
 
 res = []
 p = CHAHG1(xh,m)
 q = CHAHG2(xh,m)
 if(p is not False):
  res.append(p)
 if(q is not False):
  res.append(q)
  
 res.sort()
 sz = len(res)
 
 if(N==1):
  print("1")
  print("0 Inf")
 else:
  if(sz==2 and (res[0][1]+1 == res[1][0])):
   print("1")
   print(res[0][0],res[1][1])
  else:
   print(sz)
   for L,R in res:
    print(L,R)
 
