You have a robot that can move along a number line. At time moment $0$ it stands at point $0$.

You give $n$ commands to the robot: at time $t_i$ seconds you command the robot to go to point $x_i$. Whenever the robot receives a command, it starts moving towards the point $x_i$ with the speed of $1$ unit per second, and he stops when he reaches that point. However, while the robot is moving, it ignores all the other commands that you give him.

For example, suppose you give three commands to the robot: at time $1$ move to point $5$, at time $3$ move to point $0$ and at time $6$ move to point $4$. Then the robot stands at $0$ until time $1$, then starts moving towards $5$, ignores the second command, reaches $5$ at time $6$ and immediately starts moving to $4$ to execute the third command. At time $7$ it reaches $4$ and stops there.

You call the command $i$ successful, if there is a time moment in the range $[t_i, t_{i + 1}]$ (i. e. after you give this command and before you give another one, both bounds inclusive; we consider $t_{n + 1} = +\infty$) when the robot is at point $x_i$. Count the number of successful commands. Note that it is possible that an ignored command is successful.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. The next lines describe the test cases.

The first line of a test case contains a single integer $n$ ($1 \le n \le 10^5$) — the number of commands.

The next $n$ lines describe the commands. The $i$-th of these lines contains two integers $t_i$ and $x_i$ ($1 \le t_i \le 10^9$, $-10^9 \le x_i \le 10^9$) — the time and the point of the $i$-th command.

The commands are ordered by time, that is, $t_i < t_{i + 1}$ for all possible $i$.

The sum of $n$ over test cases does not exceed $10^5$.


-----Output-----

For each testcase output a single integer — the number of successful commands.


-----Examples-----

Input
8
3
1 5
3 0
6 4
3
1 5
2 4
10 -5
5
2 -5
3 1
4 1
5 1
6 1
4
3 3
5 -3
9 2
12 0
8
1 1
2 -6
7 2
8 3
12 -9
14 2
18 -1
23 9
5
1 -4
4 -7
6 -1
7 -3
8 -7
2
1 2
2 -2
6
3 10
5 5
8 0
12 -4
14 -7
19 -5
Output
1
2
0
2
1
1
0
2


-----Note-----

The movements of the robot in the first test case are described in the problem statement. Only the last command is successful.

In the second test case the second command is successful: the robot passes through target point $4$ at time $5$. Also, the last command is eventually successful.

In the third test case no command is successful, and the robot stops at $-5$ at time moment $7$.

Here are the $0$-indexed sequences of the positions of the robot in each second for each testcase of the example. After the cut all the positions are equal to the last one:

$[0, 0, 1, 2, 3, 4, 5, 4, 4, \dots]$

$[0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -5, \dots]$

$[0, 0, 0, -1, -2, -3, -4, -5, -5, \dots]$

$[0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 2, 2, 1, 0, 0, \dots]$

$[0, 0, 1, 0, -1, -2, -3, -4, -5, -6, -6, -6, -6, -7, -8, -9, -9, -9, -9, -8, -7, -6, -5, -4, -3, -2, -1, -1, \dots]$

$[0, 0, -1, -2, -3, -4, -4, -3, -2, -1, -1, \dots]$

$[0, 0, 1, 2, 2, \dots]$

$[0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -7, \dots]$

Difficulty: MEDIUM_HARD

Solutions:
for z in range(int(input())):
	n = int(input())
	e = [None] * n
	for i in range(n):
		e[i] = tuple(map(int, input().split()))
	i = 0
	p = 0
	res = 0
	while i < n:
		(st, tx) = e[i]
		et = st + abs(tx - p)
		if tx > p:
			dir = 1
		elif tx < p:
			dir = -1
		else:
			res += 1
			i += 1
			continue
		j = i + 1
		have = 1
		while j < n and e[j][0] < et:
			have = 0
			xx = e[j][1]
			xt = (xx - p) * dir + st
			if xt >= e[j][0] and xt <= et and (j + 1 >= n or xt <= e[j + 1][0]):
				res += 1
			j += 1
		i = j
		p = tx
		res += have
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		(t, x) = map(int, input().split())
		arr.append([t, x])
	start = 0
	end = arr[0][1]
	stime = arr[0][0]
	etime = stime + abs(end - start)
	ans = 0
	for i in range(1, n):
		if end > start:
			curr = min(arr[i][0] - stime + start, end)
			last = min(arr[i - 1][0] - stime + start, end)
			if arr[i - 1][1] >= last and arr[i - 1][1] <= curr:
				ans += 1
		else:
			curr = max(start - arr[i][0] + stime, end)
			last = max(start - arr[i - 1][0] + stime, end)
			if arr[i - 1][1] <= last and arr[i - 1][1] >= curr:
				ans += 1
		if etime <= arr[i][0]:
			start = end
			end = arr[i][1]
			stime = arr[i][0]
			etime = stime + abs(end - start)
	if end > start:
		curr = end
		last = min(arr[n - 1][0] - stime + start, end)
		if arr[n - 1][1] >= last and arr[n - 1][1] <= curr:
			ans += 1
	else:
		curr = end
		last = max(start - arr[n - 1][0] + stime, end)
		if arr[n - 1][1] <= last and arr[n - 1][1] >= curr:
			ans += 1
	print(ans)


import sys
import math, bisect, operator
(inf, m) = (float('inf'), 10 ** 9 + 7)
sys.setrecursionlimit(10 ** 5)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))

def inside(l, r, x):
	return min(l, r) <= x <= max(l, r)

def sg(x):
	return -1 if x < 0 else int(x > 0)
for _ in range(int(input())):
	n = int(input())
	qs = []
	for i in range(n):
		qs.append(list(map(int, input().split())))
	qs.append([4 * 10 ** 9, 0])
	ans = 0
	(pos, dr, lft) = (0, 0, 0)
	for i in range(n):
		(t, x) = qs[i]
		tn = qs[i + 1][0]
		if lft == 0:
			lft = abs(pos - x)
			dr = sg(x - pos)
		tmp = min(lft, tn - t)
		if inside(pos, pos + dr * tmp, x):
			ans += 1
		pos += dr * tmp
		lft -= tmp
	print(ans)


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d

def inside(l, r, x):
	return min(l, r) <= x <= max(l, r)

def sg(x):
	return -1 if x < 0 else int(x > 0)
_ = int(input())
for q in range(_):
	n = inputnum()
	qs = []
	for i in range(n):
		qs.append(list(map(int, input().split())))
	qs.append([4 * 10 ** 9, 0])
	ans = 0
	(pos, dr, lft) = (0, 0, 0)
	for i in range(n):
		(t, x) = qs[i]
		tn = qs[i + 1][0]
		if lft == 0:
			lft = abs(pos - x)
			dr = sg(x - pos)
		tmp = min(lft, tn - t)
		if inside(pos, pos + dr * tmp, x):
			ans += 1
		pos += dr * tmp
		lft -= tmp
	print(ans)


def direction(position, destination):
	diff = destination - position
	if diff == 0:
		return 0
	return int(diff / abs(diff))

def hits(pos, dir_, t_range, x):
	moved_pos = pos + t_range * dir_
	if dir_ > 0:
		if x >= pos and x <= moved_pos:
			return True
	elif x >= moved_pos and x <= pos:
		return True
	return False

def main():
	t = int(input())
	total = []
	for _ in range(t):
		n = int(input())
		cmds = []
		for _ in range(n):
			cmds.append(list(map(int, input().split())))
		cmds.append([float('inf'), 0])
		pos = 0
		t_left = 0
		dir_ = 0
		res = 0
		for i in range(n):
			(t_i, x_i) = cmds[i]
			t_j = cmds[i + 1][0]
			if t_left == 0:
				t_left = abs(x_i - pos)
				dir_ = direction(pos, x_i)
			t_range = min(t_left, t_j - t_i)
			if hits(pos, dir_, t_range, x_i):
				res += 1
			t_left -= t_range
			pos += dir_ * t_range
		total.append(res)
	for item in total:
		print(item)
main()


def solve_case():
	n = int(input())
	curr = 0
	(t, x) = map(int, input().split())
	goal = x
	ans = 0
	a = [[t, x, curr]]
	for q in range(n - 1):
		(t, x) = map(int, input().split())
		r = t - a[-1][0]
		if curr > goal:
			curr = max(curr - r, goal)
		else:
			curr = min(curr + r, goal)
		if max(curr, a[-1][2]) >= a[-1][1] >= min(curr, a[-1][2]):
			ans += 1
		if curr == goal:
			goal = x
		a.append([t, x, curr])
	if min(curr, goal) <= a[-1][1] <= max(curr, goal):
		ans += 1
	print(ans)

def main():
	for _ in range(int(input())):
		solve_case()
main()


def sign(x):
	if x == 0:
		return 0
	return 1 if x > 0 else -1

def is_between(x, f1, f2):
	if f2 < f1:
		(f1, f2) = (f2, f1)
	return f1 <= x and x <= f2

def solve(n, ts, xs):
	successfuls = command = pos = bank = 0
	moving = is_bank = False
	for i in range(n):
		(ti, xi) = (ts[i], xs[i])
		if moving:
			seconds_left = abs(pos - command)
			dt = ti - ts[i - 1]
			if seconds_left <= dt:
				pos = command
				moving = False
			else:
				pos += dt * sign(command - pos)
			if is_bank:
				is_bank = False
				if is_between(xs[i - 1], pos, bank):
					successfuls += 1
			if moving:
				is_bank = True
				bank = pos
		if not moving:
			is_bank = False
			moving = True
			command = xi
			if i == n - 1:
				successfuls += 1
				moving = False
			elif abs(command - pos) <= ts[i + 1] - ti:
				successfuls += 1
	if moving:
		if is_between(xs[-1], command, pos):
			successfuls += 1
	return successfuls

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		ts = []
		xs = []
		for i in range(n):
			(ti, xi) = map(int, input().split())
			ts.append(ti)
			xs.append(xi)
		print(solve(n, ts, xs))
main()


def main():
	n = int(input())
	t = [0] * n
	x = [0] * n
	for i in range(n):
		(t[i], x[i]) = map(int, input().split())
	xi = 0
	myi = 0
	f = 0
	tt = [False] * n
	tt[0] = True
	for i in range(1, n):
		if t[i] >= t[myi] + abs(x[myi] - xi):
			xi = x[myi]
			myi = i
			tt[i] = True
	xi = 0
	myi = 0
	t.append(100000000000)
	for i in range(0, 1):
		if x[myi] >= xi:
			x0 = t[i] - t[myi] + xi
			xk = min(t[i + 1] - t[myi] + xi, x[myi])
			if x0 <= x[i] <= xk:
				f += 1
		else:
			x0 = xi - t[i] + t[myi]
			xk = max(xi - t[i + 1] + t[myi], x[myi])
			if x0 >= x[i] >= xk:
				f += 1
	for i in range(1, n):
		if tt[i]:
			xi = x[myi]
			myi = i
		if x[myi] >= xi:
			x0 = t[i] - t[myi] + xi
			xk = min(t[i + 1] - t[myi] + xi, x[myi])
			if x0 <= x[i] <= xk:
				f += 1
		else:
			x0 = xi - t[i] + t[myi]
			xk = max(xi - t[i + 1] + t[myi], x[myi])
			if x0 >= x[i] >= xk:
				f += 1
	print(f)
rw = int(input())
for wewq in range(rw):
	main()


test = int(input())
while test:
	test -= 1
	n = int(input())
	arr = []
	cnt = 0
	for i in range(n):
		arr.append(list(map(int, input().split())))
	(i, t, c) = (0, 0, 0)
	while i < n:
		if t < arr[i][0]:
			t = arr[i][0]
		if t == arr[i][0]:
			x = arr[i][1]
			val = 1 if c < x else -1
			t += abs(c - x)
			c = x
			if i + 1 >= n or arr[i + 1][0] >= t:
				cnt += 1
		else:
			x = arr[i][1]
			t1 = arr[i][0]
			if i + 1 >= n or t < arr[i + 1][0]:
				t2 = t
			else:
				t2 = arr[i + 1][0]
			if val == 1:
				f = c - (t - t1)
				l = c - (t - t2)
			else:
				f = c + (t - t1)
				l = c + (t - t2)
			if x >= f and x <= l or (x <= f and x >= l):
				cnt += 1
		i += 1
	print(cnt)


import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
o = []
for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a += list(map(int, input().split()))
	a.append(10 ** 10)
	m = p = y = 0
	for i in range(n):
		d = a[2 * i + 2] - a[2 * i]
		v = a[2 * i + 1]
		if abs(m):
			if abs(m) <= d:
				np = p + m
				m = 0
				if p <= v <= np or p >= v >= np:
					y += 1
			else:
				if m < 0:
					m += d
					np = p - d
				else:
					m -= d
					np = p + d
				if p <= v <= np or p >= v >= np:
					y += 1
		else:
			m = v - p
			if abs(m) <= d:
				np = p + m
				m = 0
				y += 1
			elif m < 0:
				m += d
				np = p - d
			else:
				m -= d
				np = p + d
		p = np
	o.append(str(y))
print('\n'.join(o))


for j in range(int(input())):
	result = 0
	t = 0
	x = 0
	t_start = 0
	t_stop = 0
	x_dir = 0
	x_prev = 0
	x_cur = 0
	for i in range(int(input())):
		(ti, xi) = map(int, input().split())
		if ti < t_stop:
			x_cur = x_prev + (ti - t) * x_dir
		else:
			x_cur = x_prev + (t_stop - t) * x_dir
			t_start = ti
			t_stop = ti + abs(xi - x_cur)
			x_start = x_cur
			if x_start < xi:
				x_dir = 1
			elif x_start > xi:
				x_dir = -1
			else:
				x_dir = 0
		if t > 0:
			if min(x_prev, x_cur) <= x <= max(x_prev, x_cur):
				result += 1
		(t, x, x_prev) = (ti, xi, x_cur)
	if t >= t_stop or t == t_start:
		result += 1
	else:
		x_stop = x_start + (t_stop - t_start) * x_dir
		if min(x_prev, x_stop) <= x <= max(x_prev, x_stop):
			result += 1
	print(result)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	a = [L() for i in range(n)] + [[inf, 0]]
	p = 0
	v = []
	t = a[0][1]
	ws = a[0][0] + abs(a[0][1])
	for i in range(n):
		if a[i][0] >= ws:
			ws = a[i][0] + abs(p - a[i][1])
			t = a[i][1]
		v += ([p, 0],)
		p = max(t, p - (a[i + 1][0] - a[i][0])) if t <= p else min(t, p + (a[i + 1][0] - a[i][0]))
		v[-1][-1] = p
	ans = 0
	for i in range(n):
		if v[i][0] <= a[i][1] <= v[i][1] or v[i][0] >= a[i][1] >= v[i][1]:
			ans += 1
	print(ans)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def chkprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	n = int(inp())
	ml = []
	for i in range(n):
		(a, b) = mp()
		ml.append((a, b))
	dl = []
	nl = []
	k = 0
	cur = 0
	for i in range(n):
		if ml[i][0] < k:
			continue
		k = ml[i][0] + abs(cur - ml[i][1])
		dl.append((ml[i][0], ml[i][1], cur))
		nl.append(ml[i][0])
		cur = ml[i][1]
	dl.append((inf, inf, dl[-1][1]))
	nl.append(inf)
	cc = 0
	pl = []
	for i in range(n):
		x = bl(nl, ml[i][0])
		if nl[x] != ml[i][0]:
			x -= 1
		kk = dl[x][2]
		xx = abs(ml[i][0] - dl[x][0]) if dl[x + 1][2] > kk else -abs(ml[i][0] - dl[x][0])
		a = kk + xx
		pl.append((ml[i][0], a))
	pl.append((inf, dl[-1][2]))
	for i in range(n):
		cc += 1 if min(pl[i][1], pl[i + 1][1]) <= ml[i][1] <= max(pl[i][1], pl[i + 1][1]) else 0
	print(cc)


import bisect
t = int(input())
for _ in range(t):
	n = int(input())
	commands = []
	for i in range(n):
		(_t, _x) = [int(i) for i in input().split()]
		commands.append([_t, _x])
	commands.sort()
	accept = [[0, 0]]
	last_time = 0
	for command in commands:
		if len(accept) == 1 or abs(accept[-1][1] - accept[-2][1]) <= command[0] - accept[-1][0]:
			accept.append(command)
	positions = [[0, 0]]
	for (i, command) in enumerate(accept[1:]):
		if command[0] - positions[-1][0] > abs(positions[-1][1] - accept[i][1]):
			positions.append([positions[-1][0] + abs(positions[-1][1] - accept[i][1]), accept[i][1]])
		positions.append([command[0], accept[i][1]])
	positions.append([positions[-1][0] + abs(positions[-1][1] - accept[-1][1]), accept[-1][1]])
	positions.pop(0)
	l = [k[0] for k in positions]
	ans = 0

	def binary_search(value):
		return bisect.bisect(l, value - 0.1)

	def get_position(t):
		if t <= positions[0][0]:
			return 0
		elif t >= positions[-1][0]:
			return positions[-1][1]
		else:
			idx = binary_search(t)
			if positions[idx - 1][1] == positions[idx][1]:
				return positions[idx][1]
			elif positions[idx - 1][1] > positions[idx][1]:
				return positions[idx - 1][1] - (t - positions[idx - 1][0])
			else:
				return positions[idx - 1][1] + (t - positions[idx - 1][0])
	for (i, command) in enumerate(commands[:-1]):
		(t, x) = command
		t2 = commands[i + 1][0]
		x1 = get_position(t)
		x2 = get_position(t2)
		(x1, x2) = sorted([x1, x2])
		if x in range(x1, x2 + 1):
			ans += 1
	x1 = get_position(commands[-1][0])
	x2 = positions[-1][1]
	(x1, x2) = sorted([x1, x2])
	if commands[-1][1] in range(x1, x2 + 1):
		ans += 1
	print(ans)


import math
T = int(input())
for test in range(T):
	n = int(input())
	start_time = 0
	start_pos = 0
	end_time = 0
	end_pos = 0
	direction = 0
	success = 0
	queries = []
	for i in range(n):
		(t, x) = map(int, input().split(' '))
		queries.append((t, x))
	queries.append((math.inf, math.inf))
	qs = []
	for i in range(n):
		(t, x) = queries[i]
		t1 = queries[i + 1][0]
		if t >= end_time:
			start_pos = end_pos
			end_pos = x
			direction = -1 if start_pos > end_pos else int(start_pos < end_pos)
			start_time = t
			end_time = t + abs(x - start_pos)
			if end_time <= t1:
				success += 1
		else:

			def has_success():
				global start_time, start_pos, end_time, end_pos, t, x, t1
				pos1 = start_pos + direction * (t - start_time)
				t2 = min(end_time, t1)
				pos2 = start_pos + direction * (t2 - start_time)
				(pos1, pos2) = (min(pos1, pos2), max(pos1, pos2))
				if pos1 <= x <= pos2:
					return True
				else:
					return False
			if has_success():
				success += 1
	print(success)


def main():
	cases = int(input())
	ans_list = []
	for _ in range(cases):
		n = int(input())
		ans = 0
		(time, x) = map(int, input().split(' '))
		(start_time, end_time) = (0, 0)
		(start_pos, end_pos) = (0, 0)
		for i in range(n):
			if i != n - 1:
				(next_time, next_x) = map(int, input().split(' '))
			else:
				next_time = float('inf')
				next_x = float('inf')
			if time >= end_time:
				start_pos = end_pos
				end_pos = x
				start_time = time
				end_time = abs(end_pos - start_pos) + start_time
				if next_time >= end_time:
					ans += 1
			elif start_pos <= x <= end_pos or end_pos <= x <= start_pos:
				x_visit_time = abs(start_pos - x)
				if time <= start_time + x_visit_time <= next_time:
					ans += 1
			(time, x) = (next_time, next_x)
		ans_list.append(ans)
	print('\n'.join(map(str, ans_list)))
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


innum = lambda : int(input())
inmul = lambda : map(int, input().split())
instr = lambda : str(input())
inarr = lambda : list(map(int, input().split()))

def solve():
	n = innum()
	a = []
	for i in range(n):
		(j, k) = inmul()
		a.append([j, k])
	a.append([float('inf')] * 2)
	cp = 0
	dest = 0
	ans = 0
	for i in range(n):
		if cp == dest:
			dest = a[i][1]
		if dest > cp:
			add = min(a[i + 1][0] - a[i][0], dest - cp)
			if a[i][1] >= cp and a[i][1] <= cp + add:
				ans += 1
			cp += add
		else:
			add = min(a[i + 1][0] - a[i][0], cp - dest)
			if a[i][1] <= cp and a[i][1] >= cp - add:
				ans += 1
			cp -= add
	print(ans)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
import math as mt
import bisect as bi
import itertools as it
import collections as cc
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	ar = [I() for i in range(n)]
	ar.append([10 ** 27, 10 ** 27])
	f = 0
	cur = 0
	(x, y) = (0, 0)
	ans = 0
	dr = 0
	for i in range(n):
		(ti, xi) = ar[i]
		if ti < f:
			(nt, nx) = ar[i + 1]
			d = abs(x - ti)
			(l, r) = (cur + d * dr, cur + dr * (d + (min(nt, f) - ti)))
			if l > r:
				(l, r) = (r, l)
			if l <= xi <= r:
				ans += 1
		else:
			cur = y
			(x, y) = (ti, xi)
			f = ti + abs(cur - xi)
			if xi < cur:
				dr = -1
			else:
				dr = 1
			(nt, nx) = ar[i + 1]
			d = abs(x - ti)
			(l, r) = (cur + d * dr, cur + dr * (d + (nt - ti)))
			if l > r:
				(l, r) = (r, l)
			if l <= xi <= r:
				ans += 1
	print(ans)


import sys

def main():

	def modst(a, s):
		ret = 1
		while s:
			if s % 2:
				ret = ret * a % mod
			a = a * a % mod
			s //= 2
		return ret

	def Cnk(n, k):
		return (k <= n and n >= 0) * (f[n] * modst(f[k] * f[n - k] % mod, mod - 2) % mod)
	n = int(sys.stdin.readline().strip())
	q = [[0, 0]]
	for i in range(n):
		q.append(list(map(int, sys.stdin.readline().split())))
	q.sort()
	w = [0 for i in range(n + 7)]
	(res, f) = (0, 0)
	for i in range(1, n + 1):
		if q[i][0] - q[f][0] >= abs(q[f][1] - w[f]):
			w[i] = q[f][1]
			f = i
		res += int(abs(q[i][1] - w[f]) + abs(q[f][1] - q[i][1]) == abs(q[f][1] - w[f]) and q[i][0] - q[f][0] <= abs(q[i][1] - w[f]) and (i == n or abs(q[i][1] - w[f]) <= q[i + 1][0] - q[f][0]))
	print(res)
for i in range(int(input())):
	main()


import math

def func(commands):
	ans = 0
	n = len(commands)
	t_nxt = 0
	for i in range(n):
		(t, x) = commands[i]
		if t >= t_nxt:
			if i == 0:
				pos = 0
				t_nxt = t + abs(x - pos)
			else:
				pos = commands[state][1]
				t_nxt = t + abs(x - pos)
			state = i
			if state == n - 1 or t_nxt <= commands[state + 1][0]:
				ans += 1
		else:
			(ts, xs) = commands[state]
			if (x - pos) * (xs - pos) > 0:
				if abs(x - pos) <= abs(xs - pos) and abs(x - pos) >= t - ts and (i == n - 1 or abs(x - pos) <= commands[i + 1][0] - ts):
					ans += 1
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	commands = []
	for itr in range(n):
		item = list(map(int, input().split()))
		commands.append(item)
	ans = func(commands)
	print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	return x * y // gcd(x, y)
mod = 1000000007

def modInverse(b, m):
	g = gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def modu(a, b, m):
	a = a % m
	inv = modInverse(b, m)
	if inv == -1:
		return -999999999
	else:
		return inv * a % m
from math import log, sqrt, factorial, cos, tan, sin, radians, floor, ceil, log2
import bisect
from decimal import *
getcontext().prec = 8
abc = 'abcdefghijklmnopqrstuvwxyz'
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		n = ii()
		t = []
		p = []
		m = 0
		curp = 0
		curt = 0
		f = [0] * n
		for i in range(n):
			(x, y) = mi()
			t.append(x)
			p.append(y)
		ans = 0
		for i in range(n):
			if t[i] < curt:
				f[i] = 0
				x = curp - (curt - t[i]) * m
				if i == n - 1:
					if x <= p[i] and curp >= p[i] or (x >= p[i] and curp <= p[i]):
						ans += 1
				else:
					if t[i + 1] > curt:
						y = curp
					else:
						y = curp - (curt - t[i + 1]) * m
					if x <= p[i] and y >= p[i] or (x >= p[i] and y <= p[i]):
						ans += 1
			else:
				if curp < p[i]:
					m = 1
				elif curp == p[i]:
					m = 0
				else:
					m = -1
				f[i] = 1
				curt = t[i] + abs(curp - p[i])
				curp = p[i]
		if f[n - 1]:
			ans += 1
		for i in range(1, n):
			if f[i] and f[i - 1]:
				ans += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.buffer.readline
q = int(input())
for _ in range(q):
	n = int(input())
	t = []
	x = []
	p = []
	for __ in range(n):
		(tt, xx) = [int(x) for x in input().split()]
		t.append(tt)
		x.append(xx)
	t.append(float('inf'))
	x.append(0)
	p.append(0)
	prevT = t[0]
	prevX = 0
	destX = x[0]
	for i in range(1, n + 1):
		dt = t[i] - prevT
		if prevX < destX:
			currX = min(prevX + dt, destX)
		else:
			currX = max(prevX - dt, destX)
		p.append(currX)
		if currX == destX:
			prevX = currX
			destX = x[i]
			prevT = t[i]
	ans = 0
	for i in range(n):
		lower = min(p[i], p[i + 1])
		upper = max(p[i], p[i + 1])
		if lower <= x[i] <= upper:
			ans += 1
	print(ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())

def binarySearch(arr, l, r, x):
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			temp = mid
			l = mid + 1
		else:
			r = mid - 1
	return temp
for _ in range(t):
	n = int(input())
	time = []
	dist = []
	for i in range(n):
		(t, x) = list(map(int, input().split()))
		time.append(t)
		dist.append(x)
	c = 0
	d = 0
	i = 0
	ans = 0
	b = 0
	while i < n:
		e = b
		d = abs(dist[i] - e)
		a = time[i]
		b = dist[i]
		f = i
		if d == 0:
			ans += 1
			i += 1
		elif time[i] < a + d:
			while i < n and time[i] < a + d:
				if e <= b:
					if e <= dist[i] and b >= dist[i]:
						z = dist[i] - e
						ind = binarySearch(time, 0, n - 1, time[f] + z)
						if ind == i:
							ans += 1
						elif ind == i + 1 and time[f] + z == time[ind]:
							ans += 1
				elif e >= dist[i] and b <= dist[i]:
					z = e - dist[i]
					ind = binarySearch(time, 0, n - 1, time[f] + z)
					if ind == i:
						ans += 1
					elif ind == i + 1 and time[f] + z == time[ind]:
						ans += 1
				i += 1
		else:
			i += 1
	print(ans)


import sys
import bisect

def load_sys():
	return sys.stdin.readlines()

def load_local():
	with open('input.txt', 'r') as f:
		input = f.readlines()
	return input

def busy_robot(commands):
	idx_end = cur_pos = target = 0
	events = [x[0] for x in commands]
	positions = [0] + [None] * len(commands)
	ans = 0
	for i in range(len(commands)):
		if i >= idx_end:
			positions[i] = cur_pos = target
			target = commands[i][1]
			idx_end = bisect.bisect_left(events, commands[i][0] + abs(cur_pos - target))
			continue
		if cur_pos > target:
			cur_pos += events[i - 1] - events[i]
		elif cur_pos < target:
			cur_pos += events[i] - events[i - 1]
		positions[i] = cur_pos
	positions[-1] = target
	for i in range(len(commands)):
		mn = min(positions[i], positions[i + 1])
		mx = max(positions[i], positions[i + 1])
		if mn <= commands[i][1] <= mx:
			ans += 1
	return ans
input = load_sys()
TEST_CASES = []
case = []
i = 0
while i <= len(input):
	if i == len(input):
		print(busy_robot(case))
		break
	input[i] = input[i].split()
	if len(input[i]) == 1 and case:
		print(busy_robot(case))
		case = []
	elif len(input[i]) == 2:
		case.append([int(x) for x in input[i]])
	i += 1


import sys
LI = lambda : list(map(int, sys.stdin.readline().split()))
MI = lambda : map(int, sys.stdin.readline().split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline())
for _ in range(II()):
	(pt, pp, pc, d, cp) = (0, 0, 0, 0, 0)
	inp = []
	n = II()
	pos = {0: (0, 0)}
	for __ in range(n):
		(ct, cc) = MI()
		inp.append((ct, cc))
		mv = min(ct - pt, pc)
		cp = pp + mv * d
		if pt + pc < ct:
			pos[pt + pc] = cp
		pos[ct] = cp
		pc = max(0, pc - mv)
		pp = cp
		pt = ct
		if ct >= pt + pc:
			d = -1 if cc < cp else 1 if cc > cp else 0
			cc = abs(cp - cc)
			pc = cc
	ct = int(10000000000.0)
	inp.append((ct, 0))
	mv = min(ct - pt, pc)
	cp = pp + mv * d
	pos[ct] = cp
	ans = 0
	for i in range(n):
		if pos[inp[i][0]] <= inp[i][1] <= pos[inp[i + 1][0]] or pos[inp[i][0]] >= inp[i][1] >= pos[inp[i + 1][0]]:
			ans += 1
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	timer = -1
	xx = 0
	cnt = 0
	f = 0
	a = []
	for i in range(n):
		(tt, x) = map(int, input().split())
		a.append([tt, x])
	timer = a[0][0]
	lt = 0
	a.append([10 ** 13, 0])
	for i in range(n):
		if a[i][0] >= timer:
			time = abs(xx - a[i][1])
			timer = a[i][0]
			if timer + time <= a[i + 1][0]:
				cnt += 1
			lt = timer
			lx = xx
			timer += time
			xx = a[i][1]
		elif xx >= lx:
			x1 = lx + a[i][0] - lt
			te = a[i][0] + a[i][1] - x1
			if x1 <= a[i][1] and a[i][1] <= xx and (te <= a[i + 1][0]):
				cnt += 1
		else:
			x1 = lx - (a[i][0] - lt)
			te = a[i][0] + abs(a[i][1] - x1)
			if x1 >= a[i][1] and a[i][1] >= xx and (te <= a[i + 1][0]):
				cnt += 1
	print(cnt)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = int(input())
	old_x = 0
	old_t = 0
	old_target = 0
	prev_target = -1
	successful = 0
	coms = []
	for _ in range(n):
		(ti, xi) = map(int, input().split())
		coms.append((ti, xi))
	coms.append((10 ** 12, 0))
	for (ti, xi) in coms:
		dt = ti - old_t
		if abs(old_x - old_target) <= dt:
			cur_x = old_target
		elif old_x < old_target:
			cur_x = old_x + dt
		else:
			cur_x = old_x - dt
		cur_t = ti
		if old_x <= prev_target <= cur_x or cur_x <= prev_target <= old_x:
			successful += 1
		if cur_x == old_target:
			old_target = xi
		old_x = cur_x
		old_t = cur_t
		prev_target = xi
	print(successful)
t = int(input())
for _ in range(t):
	solve()


import sys

def input():
	return sys.stdin.readline().rstrip()
INF = 1e+18

def update(pos, sign, movement, previous_t, t, x):
	if sign == 0:
		if x > pos:
			return (pos, 1, x - pos)
		elif x < pos:
			return (pos, -1, pos - x)
		else:
			return (pos, 0, 0)
	elif sign == 1:
		if t - previous_t >= movement:
			if pos + movement < x:
				return (pos + movement, 1, x - (pos + movement))
			elif pos + movement > x:
				return (pos + movement, -1, pos + movement - x)
			return (pos + movement, 0, 0)
		else:
			return (pos + t - previous_t, 1, movement - (t - previous_t))
	elif t - previous_t >= movement:
		if pos - movement < x:
			return (pos - movement, 1, x - (pos - movement))
		elif pos - movement > x:
			return (pos - movement, -1, pos - movement - x)
		return (pos - movement, 0, 0)
	else:
		return (pos - t + previous_t, -1, movement - (t - previous_t))

def slv():
	n = int(input())
	command = [tuple(map(int, input().split())) for i in range(n)] + [(INF, INF)]
	(pos, sign, movement, previous_t) = (0, 0, 0, 0)
	exX = INF
	ans = 0
	for (t, x) in command:
		(new_pos, new_sign, new_movement) = update(pos, sign, movement, previous_t, t, x)
		if exX != INF:
			(l, r) = (min(new_pos, pos), max(new_pos, pos))
			if l <= exX <= r:
				ans += 1
		(pos, sign, movement, previous_t) = (new_pos, new_sign, new_movement, t)
		exX = x
	print(ans)
	return

def main():
	t = int(input())
	for i in range(t):
		slv()
	return
main()


for _ in range(int(input())):
	n = int(input())
	(busy_until, pos) = (0, 0)
	direction = True
	ans = 0
	cmds = [[int(x) for x in input().split()] for i in range(n)]
	(t, x) = ([x[0] for x in cmds], [x[1] for x in cmds])
	t.append(3 * 10 ** 9 + 7)
	for i in range(n):
		if t[i] >= busy_until:
			busy_until = t[i] + abs(pos - x[i])
			direction = pos < x[i]
		new_pos = pos + (min(busy_until, t[i + 1]) - t[i]) * (1 if direction else -1)
		ans += direction and x[i] >= pos and (x[i] <= new_pos)
		ans += not direction and x[i] <= pos and (x[i] >= new_pos)
		pos = new_pos
	print(ans)


from sys import stdin
import sys
tt = int(input())
for loop in range(tt):
	n = int(stdin.readline())
	x = []
	T = []
	for i in range(n):
		(TT, XX) = map(int, stdin.readline().split())
		x.append(XX)
		T.append(TT)
	T.append(float('inf'))
	nowx = 0
	move = 0
	dest = None
	lastT = 0
	ans = 0
	for i in range(n):
		t = T[i + 1] - T[i]
		if dest == None:
			if abs(x[i] - nowx) <= t:
				ans += 1
				nowx = x[i]
			elif nowx < x[i]:
				move = 1
				nowx += t * move
				dest = x[i]
			else:
				move = -1
				nowx += t * move
				dest = x[i]
		elif move == 1:
			if nowx <= x[i] <= min(dest, nowx + t):
				ans += 1
			nowx = min(dest, nowx + t)
			if nowx == dest:
				move = 0
				dest = None
		else:
			if max(dest, nowx - t) <= x[i] <= nowx:
				ans += 1
			nowx = max(dest, nowx - t)
			if nowx == dest:
				move = 0
				dest = None
	print(ans)


import sys
sys.setrecursionlimit(2000)
from collections import Counter
from functools import reduce

def in_range(start, stop, x):
	if start > stop:
		tmp = start
		start = stop
		stop = tmp
	return start <= x and x <= stop
t = [int(val) for val in sys.stdin.readline().split()][0]
for test in range(t):
	n = [int(val) for val in sys.stdin.readline().split()][0]
	commands = []
	for command in range(n):
		(t, x) = [int(val) for val in sys.stdin.readline().split()]
		commands.append((command, t, x))
	count = 0
	current = 0
	active_command = None
	commands += [(n, float('inf'), None)]
	for command in range(n):
		(i, t, x) = commands[command]
		next_t = commands[command + 1][1]
		if active_command == None or active_command[3] <= t:
			active_command = (current, x, t, t + abs(current - x))
			current = x
		start = active_command[0]
		dest = active_command[1]
		elapsed = t - active_command[2]
		direction = -1 if start > dest else 1
		start = start + direction * elapsed
		will_visit = in_range(start, dest, x)
		if will_visit and t + abs(start - x) <= next_t:
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	stopped = 1
	dir = 1
	d = 0
	s_t = 0
	start = 0
	pos = [0] * n
	curr_pos = 0
	end = 0
	t = []
	x = []
	s = [True] * n
	for i in range(n):
		(t1, x1) = list(map(int, input().split()))
		t.append(t1)
		x.append(x1)
	for i in range(n):
		if stopped == True:
			s[i] = True
			pos[i] = curr_pos
			start = curr_pos
			end = x[i]
			s_t = t[i]
			d = abs(x[i] - curr_pos)
			if x[i] > curr_pos:
				dir = 1
			else:
				dir = -1
			stopped = False
		elif d > t[i] - s_t:
			pos[i] = start + (t[i] - s_t) * dir
			s[i] = False
		else:
			stopped = True
			pos[i] = end
			start = pos[i]
			end = x[i]
			s_t = t[i]
			d = abs(x[i] - pos[i])
			if x[i] > pos[i]:
				dir = 1
			else:
				dir = -1
			stopped = False
	total = 0
	ind = -1
	for i in range(n - 1, -1, -1):
		if s[i] == True:
			ind = i
			break
	pos.append(x[ind])
	for i in range(0, n):
		if x[i] <= pos[i + 1] and x[i] >= pos[i] or (x[i] >= pos[i + 1] and x[i] <= pos[i]):
			total += 1
	print(total)


def inside(l, r, x):
	return min(l, r) <= x <= max(l, r)

def sg(x):
	return -1 if x < 0 else int(x > 0)

def robot(arr):
	arr.append([4 * 10 ** 9, 0])
	(pos, dr, lft) = (0, 0, 0)
	ans = 0
	for i in range(len(arr) - 1):
		(tm, x) = arr[i]
		tnext = arr[i + 1][0]
		if lft == 0:
			lft = abs(pos - x)
			dr = sg(x - pos)
		tmp = min(lft, tnext - tm)
		if inside(pos, pos + dr * tmp, x):
			ans += 1
		pos += dr * tmp
		lft -= tmp
	return ans
for i in range(int(input())):
	blanck = []
	for j in range(int(input())):
		(x, y) = map(int, input().strip().split())
		blanck.append([x, y])
	print(robot(blanck))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline()

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

def RLL():
	return list(map(int, sys.stdin.readline().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	n = N()
	res = 0
	(tl, pl) = ([], [])
	for _ in range(n):
		(i, j) = RL()
		tl.append(i)
		pl.append(j)
	(lt, nt, lp, np) = (0, 0, 0, 0)
	f = False
	for i in range(n):
		(t, p) = (tl[i], pl[i])
		if t >= nt:
			if f:
				res += 1
			f = True
			(lt, nt, lp, np) = (t, t + abs(p - np), np, p)
		else:
			f = False
			if np <= p <= lp or np >= p >= lp:
				tt = abs(p - lp) + lt
				if i == n - 1:
					ttt = float('inf')
				else:
					ttt = tl[i + 1]
				if t <= tt <= ttt:
					res += 1
	if f:
		res += 1
	print(res)


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	c = 0
	R = 0
	suc = 1
	moku = 0
	for i in range(N + 1):
		if i < N:
			(t, x) = map(int, input().split())
		else:
			(t, x) = (10 ** 18, 0)
		if i > 0:
			nc = c + hou * (t - bt)
			if min(nc, c) <= moku <= max(nc, c):
				nc = moku
			suc = nc == moku
			if min(nc, c) <= b <= max(nc, c):
				R += 1
			c = nc
		if suc:
			moku = x
			hou = 1 if moku - c > 0 else 0
			if x - c < 0:
				hou = -1
		b = x
		bt = t
	print(R)


def hugou(n):
	if n >= 0:
		return 1
	else:
		return -1
T = int(input())
INF = 10 ** 16
ans = []
for t in range(T):
	n = int(input())
	tx = [list(map(int, input().split())) for i in range(n)] + [[INF, INF]]
	place = [0] * (n + 1)
	(goal, time) = (0, -1)
	for i in range(n + 1):
		(t, x) = tx[i]
		if time > t:
			place[i] = place[i - 1] + (t - tx[i - 1][0]) * hugou(goal - place[i - 1])
		else:
			place[i] = goal
			goal = x
			time = t + abs(x - place[i])
	score = 0
	for i in range(n):
		(l, r) = (place[i], place[i + 1])
		if l > r:
			(r, l) = (l, r)
		if l <= tx[i][1] and tx[i][1] <= r:
			score += 1
	ans.append(score)
for t in range(T):
	print(ans[t])


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	t = defaultdict(lambda x: None)
	for i in range(n):
		(ti, xi) = map(int, input().split())
		t[ti] = xi
	movx = None
	prevt = None
	prevx = None
	presx = None
	ans = 0
	for ti in t.keys():
		if movx is None:
			movx = t[ti]
			prevt = ti
			prevx = movx
			presx = 0
		else:
			tempx = presx + (ti - prevt) * (1 if movx - presx > 0 else -1)
			if min(presx, tempx) <= movx <= max(presx, tempx):
				tempx = movx
			if min(presx, tempx) <= prevx <= max(presx, tempx):
				ans += 1
			presx = tempx
			if presx == movx:
				movx = t[ti]
			prevx = t[ti]
			prevt = ti
	if min(movx, presx) <= prevx <= max(movx, presx):
		ans += 1
	print(ans)


T = int(input())
r = 1
while r <= T:
	n = int(input())
	command = []
	for i in range(n):
		(t, s) = map(int, input().split())
		command.append([t, s])
	command.append([1 << 100, 0])
	time = []
	now = 0
	flag = True
	for i in range(n):
		time.append(now)
		if not flag:
			if abs(pretarget - now) <= command[i + 1][0] - command[i][0]:
				flag = True
				now = pretarget
			else:
				now += speed * (command[i + 1][0] - command[i][0])
			continue
		if command[i][1] > now:
			speed = 1
			now += command[i + 1][0] - command[i][0]
			if now >= command[i][1]:
				flag = True
				now = command[i][1]
			else:
				flag = False
				pretarget = command[i][1]
		else:
			speed = -1
			now -= command[i + 1][0] - command[i][0]
			if now <= command[i][1]:
				flag = True
				now = command[i][1]
			else:
				flag = False
				pretarget = command[i][1]
	time.append(now)
	ans = 0
	for i in range(n):
		minimum = min(time[i], time[i + 1])
		maximum = max(time[i], time[i + 1])
		if minimum <= command[i][1] <= maximum:
			ans += 1
	print(ans)
	r += 1


import sys
input = sys.stdin.buffer.readline
q = int(input())
for _ in range(q):
	n = int(input())
	t = []
	x = []
	for __ in range(n):
		(_t, _x) = [int(z) for z in input().split()]
		t.append(_t)
		x.append(_x)
	p = [0]
	currTime = t[0]
	currLocation = 0
	currDestination = x[0]
	futureTime = currTime
	for i in range(1, n):
		dt = t[i] - currTime
		if currDestination > currLocation:
			currLocation = min(currDestination, currLocation + dt)
		else:
			currLocation = max(currDestination, currLocation - dt)
		p.append(currLocation)
		if currLocation == currDestination:
			currDestination = x[i]
		currTime = t[i]
	ans = 0
	for i in range(n):
		if i + 1 < n:
			left = min(p[i], p[i + 1])
			right = max(p[i], p[i + 1])
		else:
			left = min(p[i], currDestination)
			right = max(p[i], currDestination)
		if left <= x[i] <= right:
			ans += 1
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	(p, dp, dt, lt, lp, tp) = (0, 0, 0, 0, 0, None)
	m = 1
	sucs = 0
	for k in range(n):
		(t, d) = map(int, input().split())
		p = lp + m * (min(t, dt) - lt)
		if tp != None and (tp <= p and tp >= lp or (tp >= p and tp <= lp)):
			sucs += 1
		(lp, lt, tp) = (p, t, d)
		if p == dp:
			dt = t + abs(p - d)
			dp = d
			m = 1 if dp >= p else -1
	p = lp + m * (dt - lt)
	if tp != None and (tp <= p and tp >= lp or (tp >= p and tp <= lp)):
		sucs += 1
	print(sucs)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	COM = [tuple(map(int, input().split())) for i in range(n)]
	COM.append((1 << 60, 0))
	NOW = [0, 0, 0]
	ANS = 0
	for i in range(n):
		(time, to) = COM[i]
		(ntime, nto) = COM[i + 1]
		if NOW[1] == 0:
			if NOW[0] < to:
				NOW[1] = 1
				NOW[2] = to
				NOW[0] += ntime - time
				if NOW[0] >= to:
					NOW[0] = to
					ANS += 1
					NOW[1] = 0
					NOW[2] = to
			elif NOW[0] > to:
				NOW[1] = -1
				NOW[2] = to
				NOW[0] -= ntime - time
				if NOW[0] <= to:
					NOW[0] = to
					ANS += 1
					NOW[1] = 0
					NOW[2] = to
			else:
				ANS += 1
		elif NOW[1] == 1:
			nowtemp = NOW[0]
			NOW[0] += ntime - time
			if NOW[0] >= NOW[2]:
				NOW[0] = NOW[2]
				NOW[1] = 0
			if nowtemp <= to <= NOW[0]:
				ANS += 1
		else:
			nowtemp = NOW[0]
			NOW[0] -= ntime - time
			if NOW[0] <= NOW[2]:
				NOW[0] = NOW[2]
				NOW[1] = 0
			if nowtemp >= to >= NOW[0]:
				ANS += 1
	print(ANS)


for _ in range(int(input())):
	n = int(input())
	tx = []
	for i in range(n):
		tx.append(list(map(int, input().split())))
	att = []
	stop = 0
	dstop = 0
	dir = 0
	curr = 0
	for i in range(n):
		if tx[i][0] >= stop:
			stop = tx[i][0] + abs(dstop - tx[i][1])
			curr = dstop
			if tx[i][1] > dstop:
				dir = 1
			elif tx[i][1] < dstop:
				dir = -1
			else:
				dir = 0
			dstop = tx[i][1]
		else:
			curr += dir * (tx[i][0] - tx[i - 1][0])
		att.append(curr)
	att.append(dstop)
	ans = 0
	for i in range(n):
		if att[i] <= tx[i][1] <= att[i + 1] or att[i] >= tx[i][1] >= att[i + 1]:
			ans += 1
	print(ans)


from collections import defaultdict
from sys import stdout, stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	f = 1
	c = 0
	t = []
	p = []
	for i in range(n):
		(x, y) = map(int, stdin.readline().split())
		t.append(x)
		p.append(y)
	dp = [0 for i in range(n + 1)]
	dp[0] = 0
	m = t[0] + abs(p[0])
	pe = p[0]
	qw = 0
	for i in range(1, n):
		if m <= t[i]:
			dp[i] = pe
			qw = pe
			pe = p[i]
			m = t[i] + abs(pe - qw)
		else:
			if qw < pe:
				dp[i] = qw + t[i] - t[i - 1]
			else:
				dp[i] = qw - (t[i] - t[i - 1])
			qw = dp[i]
	dp[n] = pe
	for i in range(n):
		if dp[i] <= p[i] and p[i] <= dp[i + 1] or (dp[i + 1] <= p[i] and p[i] <= dp[i]):
			c += 1
	stdout.write(str(c))
	stdout.write('\n')


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	t = int(input())
	ans_a = ['NO'] * t
	for ti in range(t):
		n = int(input())
		(pos, dest, success) = (0, 0, 0)
		commands = [tuple(map(int, input().split())) for _ in range(n)]
		for ((t1, x1), (t2, x2)) in zip(commands, commands[1:]):
			if pos < dest:
				if pos <= x1 <= min(pos + (t2 - t1), dest):
					success += 1
				pos = min(pos + (t2 - t1), dest)
			elif pos > dest:
				if max(pos - (t2 - t1), dest) <= x1 <= pos:
					success += 1
				pos = max(pos - (t2 - t1), dest)
			else:
				dest = x1
				pos += min(t2 - t1, abs(pos - dest)) * (1 if pos < dest else -1)
				if pos == dest:
					success += 1
		if pos == dest or (pos < dest and pos <= commands[-1][1] <= dest) or (pos > dest and dest <= commands[-1][1] <= pos):
			success += 1
		ans_a[ti] = str(success)
	output(*ans_a)
main()


for _ in range(int(input())):
	n = int(input())
	array = []
	for i in range(n):
		array.append(list(map(int, input().split())))
	array.append([10 ** 20, array[-1][1]])
	curr = 0
	moveTo = 0
	ans = 0
	for i in range(n):
		if curr == moveTo:
			moveTo = array[i][1]
		if curr < moveTo:
			pos = min(moveTo, curr + array[i + 1][0] - array[i][0])
			if array[i][1] <= pos and array[i][1] >= curr:
				ans += 1
		else:
			pos = max(moveTo, curr - (array[i + 1][0] - array[i][0]))
			if array[i][1] >= pos and array[i][1] <= curr:
				ans += 1
		curr = pos
	print(ans)


try:
	test = int(input())
	while test != 0:
		num = int(input())
		(time, points) = ([], [])
		for i in range(num):
			(a, b) = map(int, input().split())
			time.append(a)
			points.append(b)
		(pos, dest, ans) = (0, 0, 0)
		toReach = float('-inf')
		currT = 0
		for i in range(num):
			if (pos <= toReach and toReach <= dest) and toReach - pos <= time[i] - currT:
				ans += 1
			elif (pos >= toReach and toReach >= dest) and pos - toReach <= time[i] - currT:
				ans += 1
			if abs(dest - pos) <= time[i] - currT:
				pos = dest
			elif dest > pos:
				pos += time[i] - currT
			elif dest < pos:
				pos -= time[i] - currT
			currT = time[i]
			if pos == dest:
				dest = points[i]
			toReach = points[i]
		if pos <= toReach and toReach <= dest or (pos >= toReach and toReach >= dest):
			ans += 1
		print(ans)
		test -= 1
except EOFError as e:
	print('')


t = int(input())
for _ in range(t):
	nb_commands = int(input())
	succesful_commands = 0
	commands = [list(map(int, input().split())) for _ in range(nb_commands)]
	current_position_working_c = 0
	current_objective_working_c = 0
	current_time_beginning_working_c = 0
	current_time_end_working_c = 0
	for (i, command) in enumerate(commands):
		if commands[i][0] >= current_time_end_working_c:
			current_time_beginning_working_c = commands[i][0]
			current_time_end_working_c = commands[i][0] + abs(commands[i][1] - current_objective_working_c)
			current_position_working_c = current_objective_working_c
			current_objective_working_c = commands[i][1]
			if i == nb_commands - 1:
				succesful_commands += 1
			elif commands[i + 1][0] < current_time_end_working_c:
				pass
			else:
				succesful_commands += 1
		elif commands[i][1] <= max(current_position_working_c, current_objective_working_c) and commands[i][1] >= min(current_position_working_c, current_objective_working_c):
			time_to_reach_dream_objective = current_time_beginning_working_c + abs(current_position_working_c - commands[i][1])
			if time_to_reach_dream_objective >= commands[i][0]:
				if i == nb_commands - 1:
					succesful_commands += 1
				elif time_to_reach_dream_objective <= commands[i + 1][0]:
					succesful_commands += 1
				else:
					pass
	print(succesful_commands)


for tt in range(int(input())):
	n = int(input())
	l = [list(map(int, input().split())) for ii in range(n)]
	i = 0
	ppos = 0
	cpos = l[0][1]
	time = l[0][0] + abs(cpos)
	ptime = l[0][0]
	cnt = 0
	for i in range(n - 1):
		if l[i][0] < time:
			if cpos < ppos:
				if cpos <= l[i][1] <= ppos and l[i][0] <= ptime + abs(l[i][1] - ppos) <= l[i + 1][0]:
					cnt += 1
			elif cpos >= l[i][1] >= ppos and l[i][0] <= ptime + abs(l[i][1] - ppos) <= l[i + 1][0]:
				cnt += 1
		else:
			ppos = cpos
			cpos = l[i][1]
			time = l[i][0] + abs(cpos - ppos)
			ptime = l[i][0]
			if time <= l[i + 1][0]:
				cnt += 1
	i = n - 1
	if l[i][0] < time:
		if cpos < ppos:
			if cpos <= l[i][1] <= ppos and l[i][0] <= ptime + abs(l[i][1] - ppos):
				cnt += 1
		elif cpos >= l[i][1] >= ppos and l[i][0] <= ptime + abs(l[i][1] - ppos):
			cnt += 1
	else:
		cnt += 1
	print(cnt)


import sys
max_int = 2147483648
min_int = -max_int
tt = int(input())
for _t in range(tt):
	n = int(sys.stdin.readline())
	out = 0
	cur_x = 0
	cmd = None
	last = (0, 0)
	for nn in range(n):
		(t, x) = map(int, sys.stdin.readline().split())
		if cmd:
			cur_x = cmd[1] + (t - cmd[0]) * cmd[3]
			if cur_x > cmd[4] and cmd[3] == 1:
				stop_time = t - cur_x + cmd[4]
				cur_x = cmd[4]
			elif cur_x < cmd[4] and cmd[3] == -1:
				stop_time = t - cmd[4] + cur_x
				cur_x = cmd[4]
			else:
				stop_time = t
			was_x = cur_x - (stop_time - last[0]) * cmd[3]
			if cur_x >= last[1] >= was_x or cur_x <= last[1] <= was_x:
				out += 1
			if t >= cmd[2]:
				if cur_x == x:
					dir = 0
				elif cur_x < x:
					dir = 1
				else:
					dir = -1
				cmd = (t, cur_x, t + abs(cur_x - x), dir, x)
		else:
			if x == 0:
				dir = 0
			elif x < 0:
				dir = -1
			else:
				dir = 1
			cmd = (t, 0, t + abs(x), dir, x)
		last = (t, x)
	t = 3 * max_int
	cur_x = cmd[1] + (t - cmd[0]) * cmd[3]
	if cur_x > cmd[4] and cmd[3] == 1:
		stop_time = t - cur_x + cmd[4]
		cur_x = cmd[4]
	elif cur_x < cmd[4] and cmd[3] == -1:
		stop_time = t - cmd[4] + cur_x
		cur_x = cmd[4]
	else:
		stop_time = t
	was_x = cur_x - (stop_time - last[0]) * cmd[3]
	if cur_x >= last[1] >= was_x or cur_x <= last[1] <= was_x:
		out += 1
	print(out)


T = int(input())
for _ in range(T):
	n = int(input())
	(res, cp) = (0, 0)
	(t, x) = map(int, input().split())
	(des, ct, X) = (x, t, x)
	for i in range(n - 1):
		(t, x) = map(int, input().split())
		(et, rd) = (t - ct, abs(des - cp))
		if rd <= et:
			if min(des, cp) <= X <= max(des, cp):
				res += 1
			(cp, des) = (des, x)
		else:
			if des < cp and cp - et <= X <= cp:
				res += 1
			elif des > cp and cp <= X <= cp + et:
				res += 1
			cp = cp - et if des < cp else cp + et
		(ct, X) = (t, x)
	res += min(cp, des) <= X <= max(cp, des)
	print(res)


def diff(a, b):
	if a is None or b is None:
		return None
	else:
		return a - b

def sgn(a):
	if a < 0:
		return -1
	elif a > 0:
		return 1
	else:
		return 0

def liesBetween(x, a, b):
	return min(a, b) <= x <= max(a, b)

def calcNewY(y_prev, x, delt):
	if delt is None:
		delt = 2 * (10 ** 9 + 1)
	vel = sgn(x - y_prev)
	exp = y_prev + delt * vel
	if liesBetween(x, exp, y_prev):
		return (x, False)
	else:
		return (exp, True)

def solve():
	n = int(input().strip())
	t = [0]
	x = [0]
	for i in range(n):
		(ti, xi) = map(int, input().strip().split())
		t.append(ti)
		x.append(xi)
	t.append(None)
	x.append(None)
	ans = 0
	y = x[0]
	dest = x[0]
	moving = False
	for i in range(1, n + 1):
		if not moving:
			dest = x[i]
		(y_, moving) = calcNewY(y, dest, diff(t[i + 1], t[i]))
		if liesBetween(x[i], y, y_):
			ans += 1
		y = y_
	print(ans)
t = int(input().strip())
for _ in range(t):
	solve()


class robbot:

	def __init__(self, pos=0, time=0):
		self.p = 0
		self.t = 0
		self.moving = False
		self.direction = 1
		self.remaining = 0

	def advance_in_time(self, toreach):
		if self.moving:
			if self.t + self.remaining <= toreach:
				self.p += self.direction * self.remaining
				self.t = toreach
				self.remaining = 0
				self.moving = False
			else:
				displacement = toreach - self.t
				self.p += self.direction * displacement
				self.remaining -= displacement
				self.t = toreach
		else:
			self.t = toreach

	def order(self, t, x):
		self.advance_in_time(t)
		if not self.moving:
			self.remaining = abs(x - self.p)
			self.moving = x - self.p != 0
			if x < self.p:
				self.direction = -1
			else:
				self.direction = 1
		return self.p

	def __str__(self):
		return 't: ' + str(self.t) + '\tx: ' + str(self.p) + '\tIsMoving: ' + str(self.moving) + '\tRemaining: ' + str(self.remaining)
t = int(input())
for test in range(t):
	n = int(input())
	commands = []
	for i in range(n):
		commands.append([int(i) for i in input().split()])
	robby = robbot()
	previous_x = commands[0][1]
	isgood = 0
	new_position = robby.order(commands[0][0], commands[0][1])
	for com in commands[1:]:
		previous_position = new_position
		new_position = robby.order(com[0], com[1])
		lower_bound = min(previous_position, new_position)
		upper_bound = max(previous_position, new_position)
		if previous_x <= upper_bound and previous_x >= lower_bound:
			isgood += 1
		previous_x = com[1]
	destination = robby.p + robby.direction * robby.remaining
	lower_bound = min(destination, new_position)
	upper_bound = max(destination, new_position)
	if previous_x <= upper_bound and previous_x >= lower_bound:
		isgood += 1
	print(isgood)


import sys
import io, os
input = sys.stdin.buffer.readline
TEST = int(input())
for _ in range(TEST):
	n = int(input())
	T = []
	X = []
	TX = []
	for i in range(n):
		(t, x) = map(int, input().split())
		TX.append((t, x))
		T.append(t)
		X.append(x)
	T.append(10 ** 18)
	X.append(10 ** 18)
	pos = 0
	dir = 0
	cur = 0
	target = 0
	res = 0
	pre_x = -10 ** 18
	for i in range(n + 1):
		(t, x) = (T[i], X[i])
		if dir == 0:
			if x > pos:
				dir = 1
				cur = t
				target = x
				pre_x = x
			elif x < pos:
				dir = -1
				cur = t
				target = x
				pre_x = x
			else:
				dir = 0
				cur = t
				target = x
				pre_x = x
				res += 1
		elif dir == 1:
			if t - cur < target - pos:
				npos = pos + t - cur
				if pos <= pre_x <= npos:
					res += 1
				pos = npos
				cur = t
				pre_x = x
			else:
				dir = 0
				npos = target
				if pos <= pre_x <= npos:
					res += 1
				cur = cur + target - pos
				pos = npos
				pre_x = x
				if x > pos:
					dir = 1
					cur = t
					target = x
					pre_x = x
				elif x < pos:
					dir = -1
					cur = t
					target = x
					pre_x = x
				else:
					dir = 0
					cur = t
					target = x
					pre_x = x
					res += 1
		elif dir == -1:
			if t - cur < pos - target:
				npos = pos - (t - cur)
				if npos <= pre_x <= pos:
					res += 1
				pos = npos
				cur = t
				pre_x = x
			else:
				dir = 0
				npos = target
				if npos <= pre_x <= pos:
					res += 1
				cur = cur + pos - target
				pos = npos
				pre_x = x
				if x > pos:
					dir = 1
					cur = t
					target = x
					pre_x = x
				elif x < pos:
					dir = -1
					cur = t
					target = x
					pre_x = x
				else:
					dir = 0
					cur = t
					target = x
					pre_x = x
					res += 1
	print(res)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	(t_i, x_i) = map(int, input().split())
	pos = 0
	goal = x_i
	wait_t = t_i + abs(x_i)
	count = 0
	for _ in range(n - 1):
		(t_i_1, x_i_1) = (t_i, x_i)
		(t_i, x_i) = map(int, input().split())
		if t_i < wait_t:
			ignored = True
			diff = t_i - t_i_1
			mov = 1
			if goal < pos:
				mov = -1
			new_pos = pos + diff * mov
		else:
			ignored = False
			new_pos = goal
			goal = x_i
			wait_t = t_i + abs(new_pos - x_i)
		pos_range = [min(pos, new_pos), max(pos, new_pos)]
		if pos_range[0] <= x_i_1 <= pos_range[1]:
			count += 1
		pos = new_pos
	pos_range = [min(pos, goal), max(pos, goal)]
	if pos_range[0] <= x_i <= pos_range[1]:
		count += 1
	print(count)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	rg = []
	comm = [list(map(int, input().split())) for _ in range(n)]
	q = []
	curr = t = cnt = 0
	for i in range(n):
		(ti, xi) = comm[i]
		if t <= ti:
			rg.append((curr, xi, ti, ti + abs(xi - curr)))
			(t, curr) = (rg[-1][3], xi)
			if i == n - 1:
				cnt += 1
			else:
				(tj, xj) = comm[i + 1]
				if t <= tj or rg[-1][0] == curr:
					cnt += 1
		else:
			(prev, curr, t1, t2) = rg[-1]
			(tx, x) = comm[i]
			if i < n - 1:
				tu = comm[i + 1][0]
			else:
				tu = t2
			if prev <= curr:
				(f, b) = (curr - (t2 - tx), curr - max(t2 - tu, 0))
				if f <= x <= b:
					cnt += 1
			else:
				(f, b) = (curr + max(t2 - tu, 0), curr + t2 - tx)
				if f <= x <= b:
					cnt += 1
	return cnt
for _ in range(int(input())):
	print(solve())


import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq

def input():
	return sys.stdin.readline()[:-1]

def solve(N, T):
	p = 0
	processing = False
	current_command_x = 0
	successful_command_count = 0
	for i in range(N):
		t = T[i][0]
		x = T[i][1]
		td = T[i + 1][0] - T[i][0]
		if not processing:
			if abs(x - p) <= td:
				p = x
				processing = False
				successful_command_count += 1
			else:
				processing = True
				current_command_x = x
				if p < x:
					p += td
				else:
					p -= td
		else:
			p1 = 0
			if abs(current_command_x - p) <= td:
				processing = False
				p1 = current_command_x
			elif p <= current_command_x:
				p1 = p + td
			else:
				p1 = p - td
			if p <= x <= p1 or p1 <= x <= p:
				successful_command_count += 1
			p = p1
	return successful_command_count

def main():
	T0 = int(input())
	for _ in range(T0):
		N = int(input())
		T = []
		for _ in range(N):
			(t, x) = map(int, input().split())
			T.append((t, x))
		T.append((10 ** 10, 0))
		ans = solve(N, T)
		print(ans)
main()


T = int(input())
A = []
for _ in range(T):
	n = int(input())
	tx = [tuple(map(int, input().split())) for i in range(n)]
	if n == 1:
		A.append(1)
		continue
	pos = 0
	time = 0
	ans = 0
	prev = 0
	target = 0
	cur = 0
	k = 0
	if abs(tx[0][1]) <= tx[1][0] - tx[0][0]:
		ans += 1
	target = tx[0][1]
	if tx[0][1] > 0:
		k = 1
	else:
		k = -1
	time = abs(tx[0][1]) + tx[0][0]
	for i in range(1, n - 1):
		(t, x) = tx[i]
		if time <= t:
			cur = target
			target = x
			if abs(target - cur) <= tx[i + 1][0] - t:
				ans += 1
			elif target > cur:
				k = 1
			else:
				k = -1
			time = t + abs(target - cur)
		else:
			cur += k * (t - tx[i - 1][0])
			if cur <= x <= min(target, cur + k * (tx[i + 1][0] - t)) or max(target, cur + k * (tx[i + 1][0] - t)) <= x <= cur:
				ans += 1
	if time <= tx[-1][0]:
		ans += 1
	else:
		cur += k * (tx[-1][0] - tx[-2][0])
		if cur <= tx[-1][1] <= target or target <= tx[-1][1] <= cur:
			ans += 1
	A.append(ans)
print(*A, sep='\n')


import math
import bisect
import heapq
from functools import lru_cache

def readStr():
	return input()

def readInt():
	return int(input())

def readStrs():
	return input().split(' ')

def readInts():
	return [int(x) for x in readStrs()]

def solve(n, a):
	ans = 0
	(x1, x2) = (0, 0)
	(t1, t2) = (0, 0)
	for i in range(n):
		(ti, xi) = a[i]
		if ti < t2:
			tn = min(t2, a[i + 1][0]) if i < n - 1 else t2
			s = 1 if x2 > x1 else -1
			y1 = x1 + s * (ti - t1)
			y2 = x1 + s * (tn - t1)
			if y1 <= xi <= y2 or y2 <= xi <= y1:
				ans += 1
		else:
			x1 = x2
			t1 = ti
			x2 = xi
			t2 = t1 + abs(x2 - x1)
			if i == n - 1 or a[i + 1][0] >= t2:
				ans += 1
	return ans
tc = readInt()
for ti in range(tc):
	n = readInt()
	a = []
	for _ in range(n):
		(t, x) = readInts()
		a.append((t, x))
	ans = solve(n, a)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [0] * (n + 1)
	ans = 0
	for i in range(n):
		a[i] = list(map(int, input().split()))
	a[n] = [10 ** 10]
	t = a[0][0]
	p = 0
	for i in range(n):
		if a[i][0] >= t:
			t_pre = a[i][0]
			t = a[i][0] + abs(a[i][1] - p)
			if t <= a[i + 1][0]:
				ans += 1
			if a[i][1] >= p:
				c = 1
			else:
				c = -1
			p_pre = p
			p = a[i][1]
		else:
			tt = t_pre + abs(a[i][1] - p_pre)
			pp = p_pre + c * (a[i][0] - t_pre)
			if c == 1:
				if p >= a[i][1] and a[i][1] >= pp and (tt <= a[i + 1][0]):
					ans += 1
			elif p <= a[i][1] and a[i][1] <= pp and (tt <= a[i + 1][0]):
				ans += 1
	print(ans)


def main():
	from sys import stdin
	from random import randint, choice, shuffle
	from functools import lru_cache
	input = stdin.readline
	for _ in range(int(input())):
		n = int(input())
		x = []
		t = []
		for i in range(n):
			(a, b) = map(int, input().split())
			t.append(a)
			x.append(b)
		t.append(10 ** 10)
		i = 0
		j = 0
		cur = 0
		cnt = 0
		while i < n:
			d = x[i]
			while j < n and cur != d:
				if cur < d:
					if cur <= x[j] <= min(d, cur + t[j + 1] - t[j]):
						cnt += 1
					cur = min(d, cur + t[j + 1] - t[j])
				else:
					if max(d, cur - t[j + 1] + t[j]) <= x[j] <= cur:
						cnt += 1
					cur = max(d, cur - t[j + 1] + t[j])
				j += 1
			if i == j:
				cnt += 1
				i += 1
				j += 1
			else:
				i = j
		print(cnt)
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	A = [list(map(int, input().split())) for _ in range(n)] + [[float('inf'), float('inf')]]
	valid = [1] * n
	(pos, cur) = (0, 0)
	ans = 0
	for (i, (t, x)) in enumerate(A[:-1]):
		if t < cur:
			valid[i] = 0
			start = pre + flag * (t - pre_t)
			end = pre + flag * (min(A[i + 1][0], cur) - pre_t)
			if min(start, end) <= x <= max(start, end):
				ans += 1
		else:
			cur = t + abs(pos - x)
			pre = pos
			pre_t = t
			pos = x
			if A[i + 1][0] >= cur:
				ans += 1
			flag = 1 if x >= pre else -1
	print(ans)


import sys
input = sys.stdin.readline
import math
import copy
for _ in range(int(input())):
	n = int(input())
	commands = []
	for i in range(n):
		commands.append(list(map(int, input().split())))
	commands.append([10 ** 18, 0])
	i = 0
	current = 0
	pos = 0
	ans = 0
	while i < n:
		start = commands[i][0]
		time = abs(pos - commands[current][1])
		finish = start + time
		if finish <= commands[i + 1][0]:
			endpos = commands[current][1]
			if commands[i][1] >= min(pos, endpos) and commands[i][1] <= max(pos, endpos):
				ans += 1
			pos = endpos
			current = i + 1
		else:
			time = commands[i + 1][0] - start
			if commands[current][1] < pos:
				endpos = pos - time
				if commands[i][1] >= min(pos, endpos) and commands[i][1] <= max(pos, endpos):
					ans += 1
				pos = endpos
			else:
				endpos = pos + time
				if commands[i][1] >= min(pos, endpos) and commands[i][1] <= max(pos, endpos):
					ans += 1
				pos = endpos
		i += 1
	print(ans)


import sys, os, getpass
import heapq as hq
import math, random, functools, itertools
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve_(commands):
	commands = sorted(commands)
	cur = 0
	booked = 0
	visited = [(-10 ** 10, 0), (-10 ** 10, 0)]
	for (t, x) in commands:
		if t < booked:
			continue
		else:
			visited.append((t, cur))
			dist = abs(x - cur)
			visited.append((t + dist, x))
			booked = t + dist
			cur = x
	visited.append((2 * 10 ** 10, visited[-1][1]))
	ignored = commands
	ignored.append((10 ** 10, ignored[-1][0]))

	def interpolate(x1, x2, y1, y2, x):
		return y1 + (x - x1) * (y2 - y1) / (x2 - x1)
	ptr = 0
	successful = 0
	for ((t1, x), (t2, _)) in zip(ignored, ignored[1:]):
		while visited[ptr + 1][0] < t1:
			ptr += 1
		((x1, y1), (x2, y2)) = (visited[ptr], visited[ptr + 1])
		loc = interpolate(x1, x2, y1, y2, t1)
		posmax = loc
		posmin = loc
		while visited[ptr + 1][0] < t2:
			posmax = max(posmax, visited[ptr + 1][1])
			posmin = min(posmin, visited[ptr + 1][1])
			ptr += 1
		((x1, y1), (x2, y2)) = (visited[ptr], visited[ptr + 1])
		loc = interpolate(x1, x2, y1, y2, t2)
		posmax = max(posmax, loc)
		posmin = min(posmin, loc)
		if posmin <= x <= posmax:
			successful += 1
	return successful

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]
for case_num in range(int(input())):
	k = int(input())
	mrr = read_matrix(k)
	res = solve(mrr)
	print(res)


from collections import deque, Counter, defaultdict
from bisect import bisect_left, bisect_right
import heapq
from math import gcd, floor, ceil
import sys
MOD = 10 ** 9 + 7

def input():
	return sys.stdin.readline().rstrip()
INF = 1 << 60

def solve():
	n = int(input())
	Command = [tuple(map(int, input().split())) for i in range(n)]
	pos = 0
	Left_distance = 0
	(now_time, next_time) = (0, 0)
	ans = 0
	for idx in range(n):
		now_time = Command[idx][0]
		if idx < n - 1:
			next_time = Command[idx + 1][0]
		elif idx == n - 1:
			next_time = INF
		if Left_distance == 0:
			Left_distance += Command[idx][1] - pos
			req_time = abs(next_time - now_time)
			if abs(Left_distance) <= req_time:
				ans += 1
				pos = Command[idx][1]
				Left_distance = 0
				continue
			elif Left_distance < 0:
				pos -= req_time
				Left_distance += req_time
				continue
			elif Left_distance > 0:
				pos += req_time
				Left_distance -= req_time
				continue
		elif Left_distance > 0:
			req_time = abs(next_time - now_time)
			if Left_distance <= req_time:
				m = pos
				M = pos + Left_distance
				ans += m <= Command[idx][1] <= M
				pos = M
				Left_distance = 0
				continue
			elif Left_distance > req_time:
				m = pos
				M = pos + req_time
				ans += m <= Command[idx][1] <= M
				pos = M
				Left_distance -= req_time
				continue
		elif Left_distance < 0:
			req_time = abs(next_time - now_time)
			if abs(Left_distance) <= req_time:
				M = pos
				m = pos + Left_distance
				ans += m <= Command[idx][1] <= M
				pos = m
				Left_distance = 0
				continue
			elif abs(Left_distance) > req_time:
				M = pos
				m = pos - req_time
				ans += m <= Command[idx][1] <= M
				pos = m
				Left_distance += req_time
				continue
	print(ans)
	return

def main():
	T = int(input())
	for _ in range(T):
		solve()
	return
main()


t = int(input())
for test in range(t):
	n = int(input())
	meirei = [list(map(int, input().split())) for i in range(n)]
	if n == 1:
		print(1)
		continue
	pre = 0
	now = 0
	time = meirei[0][0]
	ans = 0
	dir = 0
	if meirei[0][1] > 0:
		dir = 1
	elif meirei[0][1] < 0:
		dir = -1
	target = meirei[0][1]
	gan = target
	for (x, y) in meirei[1:]:
		pre = now
		if dir == 0:
			now = pre
		elif dir == 1:
			now = min(target, pre + dir * (x - time))
		else:
			now = max(target, pre + dir * (x - time))
		if pre <= gan <= now or now <= gan <= pre:
			ans += 1
		time = x
		if now == target:
			if now == y:
				dir = 0
			elif now > y:
				dir = -1
			else:
				dir = 1
			target = y
		gan = y
	pre = now
	if dir == 0:
		now = pre
	elif dir == 1:
		now = min(target, pre + dir * (10 ** 18 - time))
	else:
		now = max(target, pre + dir * (10 ** 18 - time))
	if pre <= gan <= now or now <= gan <= pre:
		ans += 1
	print(ans)


import sys
input = sys.stdin.readline

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def main():
	for _ in range(int(input())):
		n = int(input())
		tx = []
		for i in range(n):
			tx.append(list(map(int, input().split())))
		att = []
		stop = 0
		dstop = 0
		dir = 0
		curr = 0
		for i in range(n):
			if tx[i][0] >= stop:
				stop = tx[i][0] + abs(dstop - tx[i][1])
				curr = dstop
				if tx[i][1] > dstop:
					dir = 1
				elif tx[i][1] < dstop:
					dir = -1
				else:
					dir = 0
				dstop = tx[i][1]
			else:
				curr += dir * (tx[i][0] - tx[i - 1][0])
			att.append(curr)
		att.append(dstop)
		ans = 0
		for i in range(n):
			if att[i] <= tx[i][1] <= att[i + 1] or att[i] >= tx[i][1] >= att[i + 1]:
				ans += 1
		print(ans)
	return
main()


import sys, os, io
input = sys.stdin.readline
ans = []
T = int(input())
for t in range(T):
	n = int(input())
	(time, pos) = ([0] * n, [0] * n)
	for i in range(n):
		(time[i], pos[i]) = map(int, input().split())
	robot = [0] * n
	src = tgt = arrive = leave = 0
	dire = 1
	for i in range(n):
		if time[i] >= arrive:
			robot[i] = tgt
			dire = int(pos[i] > tgt) * 2 - 1
			(leave, arrive) = (time[i], time[i] + abs(pos[i] - tgt))
			(src, tgt) = (tgt, pos[i])
		else:
			robot[i] = src + (time[i] - leave) * dire
	robot.append(tgt)
	print(sum((int(robot[i] <= pos[i] <= robot[i + 1] or robot[i] >= pos[i] >= robot[i + 1]) for i in range(n))))


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(ii()):
		n = ii()
		a = []
		for i in range(n):
			a.append(li())
		(curl, curr) = (0, 0)
		(dl, dr) = (0, 0)

		def check(tl, tr, x):
			if dr == x and tr >= curr:
				return 1
			if min(dl, dr) <= x <= max(dl, dr):
				if dr > dl:
					time = curl + abs(x - dl)
				else:
					time = curl + abs(x - dl)
				return tl <= time <= tr
			else:
				return 0
		ans = 0
		for i in range(n):
			if a[i][0] >= curr:
				curl = a[i][0]
				curr = curl + abs(dr - a[i][1])
				dl = dr
				dr = a[i][1]
			tl = a[i][0]
			tr = 10000000000.0
			if i < n - 1:
				tr = a[i + 1][0]
			ans += check(tl, tr, a[i][1])
		print(ans)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


from sys import stdin
T = int(stdin.readline().strip())
for caso in range(T):
	n = int(stdin.readline().strip())
	s = [list(map(int, stdin.readline().strip().split())) for i in range(n)]
	s.append([10 ** 10, 10 ** 10])
	x = 0
	t = 0
	ind = 0
	ans = 0
	while ind < n:
		t = s[ind][0]
		t1 = t
		x1 = x
		y = abs(x - s[ind][1])
		t = t + y
		x = s[ind][1]
		lim = [x1, x]
		lim.sort()
		ind1 = ind
		while ind < n and s[ind][0] < t:
			t2 = t1 + abs(x1 - s[ind][1])
			if t2 >= s[ind][0] and t2 <= s[ind + 1][0] and (s[ind][1] >= lim[0]) and (s[ind][1] <= lim[1]):
				ans += 1
			ind += 1
		if ind1 == ind:
			t2 = t1 + abs(x1 - s[ind][1])
			if t2 >= s[ind][0] and t2 <= s[ind + 1][0] and (s[ind][1] >= lim[0]) and (s[ind][1] <= lim[1]):
				ans += 1
			ind += 1
	print(ans)


import sys
for _ in range(int(sys.stdin.readline().strip())):
	n = int(sys.stdin.readline().strip())
	b = []
	for i in range(n):
		a = list(map(int, sys.stdin.readline().strip().split(' ')))
		b.append(a)
	b.append([10 ** 12, 0])
	pos = [0, 0, 0]
	s = 0
	for (i, el) in enumerate(b[:-1]):
		start = el[0]
		end = b[i + 1][0]
		if abs(pos[2] - pos[0]) + pos[1] <= start:
			pos = [pos[2], el[0], el[1]]
		if pos[2] > pos[0]:
			if min(pos[0] + start - pos[1], pos[2]) <= el[1] <= min(pos[2], pos[0] + end - pos[1]):
				s += 1
		if pos[2] <= pos[0]:
			if max(pos[2], pos[0] - (end - pos[1])) <= el[1] <= max(pos[2], pos[0] - (start - pos[1])):
				s += 1
	print(s)


from sys import stdin, stdout
import math
from functools import reduce

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		commands = []
		for _ in range(n):
			arr = list(map(int, stdin.readline().split()))
			commands.append(arr)
		commands.append([10000000000, 1000000000])
		until = -1
		prev_time = 0
		prev_dest = 0
		dest = 0
		is_interrupt = False
		success_cnt = 0
		for i in range(n):
			(time, pos) = commands[i]
			if until == -1:
				until = abs(dest - pos) + time
				prev_time = time
				prev_dest = dest
				dest = pos
				continue
			if time < until:
				is_interrupt = True
				if prev_dest <= dest:
					dist = time - prev_time
				else:
					dist = prev_time - time
				current_pos = prev_dest + dist
				time_to_take = pos - current_pos
				dest_pos = current_pos + time_to_take
				if prev_dest > dest:
					time_to_take *= -1
				if time_to_take < 0 or time + time_to_take > commands[i + 1][0]:
					continue
				if dest_pos == pos and time + time_to_take <= until:
					success_cnt += 1
				continue
			if not is_interrupt:
				success_cnt += 1
			until = abs(dest - pos) + time
			prev_time = time
			prev_dest = dest
			dest = pos
			is_interrupt = False
		if not is_interrupt:
			success_cnt += 1
		stdout.write(str(success_cnt) + '\n')
main()


import sys
import bisect
input = sys.stdin.readline
t = int(input())
for you in range(t):
	n = int(input())
	l = []
	for i in range(n):
		z = input().split()
		u = int(z[0])
		v = int(z[1])
		l.append((u, v))
	l.append((10 ** 18, 0))
	counter = 0
	currtime = 0
	currpos = 0
	reqtime = 0
	reqpos = 0
	for i in range(n):
		if reqtime <= l[i][0]:
			currtime = l[i][0]
			currpos = reqpos
			reqtime = currtime + abs(currpos - l[i][1])
			reqpos = l[i][1]
			if abs(reqpos - currpos) + currtime <= l[i + 1][0]:
				counter += 1
		else:
			if (reqpos - currpos) * (l[i][1] - currpos) < 0:
				continue
			if abs(reqpos - currpos) < abs(l[i][1] - currpos):
				continue
			z = currtime + abs(l[i][1] - currpos)
			if z >= l[i][0] and z <= l[i + 1][0]:
				counter += 1
	print(counter)


from collections import defaultdict, Counter
import sys
import bisect

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	l = []
	for _ in range(n):
		(t, x) = get_ints()
		l.append((t, x))
	arr = [0]
	if l[0][1] >= 0:
		pos = True
	else:
		pos = False
	to_reach = l[0][1]
	for i in range(1, n):
		time_elapsed = l[i][0] - l[i - 1][0]
		if time_elapsed >= abs(to_reach - arr[-1]):
			arr.append(to_reach)
			if to_reach >= l[i][1]:
				pos = False
			else:
				pos = True
			to_reach = l[i][1]
		elif pos:
			arr.append(arr[-1] + time_elapsed)
		else:
			arr.append(arr[-1] - time_elapsed)
	l.append((0, abs(to_reach - arr[-1])))
	arr.append(to_reach)
	ans = 0
	for i in range(1, n + 1):
		if arr[i] >= l[i - 1][1] and arr[i - 1] <= l[i - 1][1] or (arr[i] <= l[i - 1][1] and arr[i - 1] >= l[i - 1][1]):
			ans += 1
	print(ans)


import sys
t = int(sys.stdin.readline())
for tt in range(t):
	n = int(sys.stdin.readline())
	p0 = 0
	pn = 0
	t0 = 0
	tn = 0
	v = 1
	succ = 0
	active_may_succ = True
	prev_ti = 0
	prev_xi = 0
	for i in range(n):
		(ti, xi) = [int(x) for x in sys.stdin.readline().split()]
		if ti >= tn:
			if active_may_succ:
				succ += 1
			elif prev_ti - t0 <= v * (prev_xi - p0) and v * (prev_xi - p0) <= tn - t0:
				succ += 1
			if pn > xi:
				v = -1
			else:
				v = 1
			p0 = pn
			t0 = ti
			time_to_succ = abs(xi - p0)
			tn = t0 + time_to_succ
			pn = xi
			active_may_succ = True
		else:
			if not active_may_succ:
				if prev_ti - t0 <= v * (prev_xi - p0) and v * (prev_xi - p0) <= ti - t0:
					succ += 1
			active_may_succ = False
			prev_ti = ti
			prev_xi = xi
	if active_may_succ:
		succ += 1
	elif prev_ti - t0 <= v * (prev_xi - p0) and v * (prev_xi - p0) <= tn - t0:
		succ += 1
	print(succ - 1)


for k in range(int(input())):
	n = int(input())
	ls = []
	for i in range(n):
		ls.append(list(map(int, input().split())))
	ls.append([1e+50, 0])
	pos = 0
	ts = 0
	te = 0
	ans = 0
	v = 0
	for i in range(n):
		if te > ls[i][0]:
			pos = (ls[i][0] - ts) * v + pos
			ts = ls[i][0]
		else:
			pos = (te - ts) * v + pos
			ts = ls[i][0]
			te = abs(ls[i][1] - pos) + ts
			v = 0 if ls[i][1] == pos else abs(ls[i][1] - pos) // (ls[i][1] - pos)
		nextt = ls[i + 1][0]
		if nextt > te:
			nextpos = (te - ts) * v + pos
		else:
			nextpos = (nextt - ts) * v + pos
		if pos <= ls[i][1] <= nextpos or nextpos <= ls[i][1] <= pos:
			ans += 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from math import inf
for _ in range(int(input()) if True else 1):
	n = int(input())
	tx = []
	for i in range(n):
		(t, x) = map(int, input().split())
		tx += [[t, x]]
	tx += [[inf, 69]]
	pos = 0
	time = 0
	next_command = 0
	ans = 0
	i = 0
	while i < n:
		(t, x) = tx[i]
		j = i
		if t >= next_command:
			next_command = t + abs(pos - x)
			if abs(pos - x) <= tx[i + 1][0] - t:
				ans += 1
			j += 1
			while j < n:
				if next_command > tx[j][0]:
					(t2, x2) = tx[j]
					(t3, x3) = tx[j + 1]
					if pos <= x2 <= x or pos >= x2 >= x:
						if t2 <= t + abs(pos - x2) <= t3:
							ans += 1
				else:
					j -= 1
					break
				j += 1
			pos = x
		i = j + 1
	print(ans)


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

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

def FIP():
	return map(float, stdin.readline().split())

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj

def sieve():
	li = [True] * (10 ** 3 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	(prime, cur) = ([0] * 200, 0)
	for i in range(10 ** 3 + 5):
		if li[i] == True:
			prime[cur] = i
			cur += 1
	return prime

def SPF():
	mx = 10 ** 6 + 1
	spf[1] = 1
	for i in range(2, mx):
		if spf[i] == 1000000000.0:
			spf[i] = i
			for j in range(i * i, mx, i):
				if i < spf[j]:
					spf[j] = i
	return

def prime(n, d):
	prm = set()
	while n != 1:
		prm.add(spf[n])
		n = n // spf[n]
	for ele in prm:
		d[ele] = d.get(ele, 0) + 1
	return

def primeFactors(n, d):
	while n % 2 == 0:
		d[2] = d.get(2, 0) + 1
		n = n / 2
	for i in range(3, int(mt.sqrt(n)) + 1, 2):
		while n % i == 0:
			d[i] = d.get(i, 0) + 1
			n = n / i
	if n > 2:
		d[n] = d.get(n, 0) + 1
	return
mod = 998244353

def solve():
	n = II()
	li = []
	for i in range(n):
		(t, x) = IP()
		li.append([t, x])
	(last, cur) = (0, 0)
	cur_time = 0
	suc = 0
	for i in range(n):
		(t, x) = (li[i][0], li[i][1])
		if t < cur_time:
			if x >= min(last, cur) and x <= max(last, cur):
				when_was_i_here = cur_time - abs(cur - x)
				if i < n - 1:
					if when_was_i_here <= li[i + 1][0] and when_was_i_here >= li[i][0]:
						suc += 1
				elif when_was_i_here >= li[i][0]:
					suc += 1
		else:
			dist = abs(x - cur)
			last = cur
			cur = x
			cur_time = t + dist
			if i < n - 1:
				if cur_time <= li[i + 1][0]:
					suc += 1
			else:
				suc += 1
	print(suc)
	return
t = II()
for i in range(t):
	solve()


test = int(input())
for sdfas in range(test):
	n = int(input())
	(tp, xp) = map(int, input().split())
	pos = 0
	target = xp
	ans = 0
	for i in range(n - 1):
		(tc, xc) = map(int, input().split())
		if tc - tp >= abs(target - pos):
			if target <= xp <= pos or target >= xp >= pos:
				ans += 1
			pos = target
			(tp, xp) = (tc, xc)
			target = xp
		else:
			newpos = pos + (tc - tp) * (1 if target > pos else -1)
			if newpos <= xp <= pos or newpos >= xp >= pos:
				ans += 1
			pos = newpos
			(tp, xp) = (tc, xc)
	if pos <= xp <= target or pos >= xp >= target:
		ans += 1
	print(ans)