Read problems statements in Mandarin Chinese  and Russian. 

N one dimensional kingdoms are represented as intervals of the form [a_{i} , b_{i}] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L 
≤ x ≤ R.

Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.

------ Input ------ 

First line of the input contains T denoting number of test cases.

For each test case, first line contains N denoting the number of one dimensional kingdoms.

For each next N lines, each line contains two space separated integers a_{i} and b_{i}.

------ Output ------ 

For each test case , output an integer denoting the minimum  number of bombs required.

------ Constraints ------ 

Subtask 1 (20 points) : 1 ≤ T ≤ 100 , 1 ≤ N ≤ 100 , 0 ≤ a_{i} ≤ b_{i} ≤500  
Subtask 2 (30 points) : 1 ≤ T ≤ 100 , 1 ≤ N ≤ 1000 , 0 ≤ a_{i} ≤ b_{i} ≤ 1000   
Subtask 3 (50 points) : 1 ≤ T ≤ 20 , 1 ≤ N ≤ 10^{5}, 0 ≤ a_{i} ≤ b_{i} ≤ 2000 

----- Sample Input 1 ------ 
1
3
1 3
2 5
6 9
----- Sample Output 1 ------ 
2
----- explanation 1 ------ 
There are three kingdoms [1,3] ,[2,5] and [6,9]. You will need at least 2 bombs 
to destroy the kingdoms. In one of the possible solutions, you can place two bombs at x = 2 and x = 6 .

Difficulty: MEDIUM_HARD

Solutions:
try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		dictk = [-1] * 2001
		for o in range(n):
			(a, b) = map(int, input().split())
			dictk[b] = max(dictk[b], a)
		maxk = -1
		res = 0
		for i in range(0, 2001):
			if maxk < dictk[i]:
				res += 1
				maxk = i
		print(res)
except:
	pass


T = int(input())
for i in range(T):
	N = int(input())
	array = []
	for j in range(N):
		l = input()
		array.append([int(i) for i in l.split()])
	array = sorted(array)
	count = 1
	point = array[0][1]
	for j in range(1, N):
		if array[j][0] <= point:
			point = min(point, array[j][1])
		else:
			point = array[j][1]
			count += 1
	print(count)


import math
from math import log2, sqrt
import sys
from sys import stdin, stdout
import os
sys.setrecursionlimit(pow(10, 6))
import collections
from collections import defaultdict
from statistics import median
inf = float('inf')

def present(x, y, lista):
	return x <= lista[1] and y >= lista[0]

def get(x, y, lista):
	left = max(x, lista[0])
	right = min(y, lista[1])
	return [left, right]
t = int(input())
for i in range(t):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	l.sort()
	bombs = 1
	x = l[0][0]
	y = l[0][1]
	for i in range(1, len(l)):
		if present(x, y, l[i]):
			(x, y) = get(x, y, l[i])
		else:
			bombs += 1
			(x, y) = (l[i][0], l[i][1])
	print(bombs)


T = int(input())
for t in range(T):
	N = int(input())
	kingdoms = [[int(x) for x in input().split()] for n in range(N)]
	kingdoms.sort(key=lambda x: x[1])
	ans = 0
	newmax = -1
	for i in range(len(kingdoms)):
		if kingdoms[i][0] > newmax:
			ans += 1
			newmax = kingdoms[i][1]
	print(ans)


for _ in range(int(input())):
	N = int(input())
	a = []
	for i in range(N):
		a.append(list(map(int, input().split())))
	a.sort(key=lambda x: x[1])
	ans = 0
	k = -1
	for i in range(N):
		l = a[i][0]
		r = a[i][1]
		if l > k:
			ans += 1
			k = r
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	a.sort()
	m = 1
	x = a[0][1]
	for i in a[1:]:
		s = i[0]
		e = i[1]
		if s > x:
			m += 1
			x = e
		else:
			x = min(x, e)
	print(m)


def minBombs(kds):
	bombs = 0
	end = kds[0][1]
	for kd in kds[1:]:
		if kd[0] > end:
			bombs += 1
			end = kd[1]
		else:
			end = min(end, kd[1])
	bombs += 1
	return bombs
T = int(input())
for t in range(T):
	N = int(input())
	kds = []
	for n in range(N):
		(a, b) = map(int, input().split())
		kds.append([a, b])
	kds.sort(key=lambda kd: kd[0])
	print(minBombs(kds))


for _ in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		(d, b) = map(int, input().split())
		a.append([b, d])
	a.sort()
	c = 1
	if n == 1:
		print(1)
	f = a[0][0]
	for i in range(1, len(a)):
		if f < a[i][1]:
			c += 1
			f = a[i][0]
	print(c)


m = int(input())
for t in range(m):
	n = int(input())
	a = []
	for i in range(n):
		a.append(list(map(int, input().split())))
	a.sort()
	c = 0
	temp = None
	for i in a:
		if temp is None:
			temp = i
		elif i[0] > temp[1]:
			c += 1
			temp = i
		elif i[1] < temp[1]:
			temp = i
		else:
			temp = [i[0], temp[1]]
	print(c + 1)


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		(a, b) = map(int, input().split())
		l.append((a, b))
	ans = 1
	l.sort(key=lambda x: x[1])
	last = l[0][1]
	for p in range(1, n):
		if l[p][0] > last:
			ans += 1
			last = l[p][1]
	print(ans)


def ss(l):
	n = len(l)
	l = sorted(l, key=lambda x: x[1])
	ans = 0
	b = -float('inf')
	for i in range(n):
		(x, y) = l[i]
		if x > b:
			ans += 1
			b = y
	return ans
for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	print(ss(l))


for _ in range(int(input())):
	n = int(input())
	l = []
	(a, r, c) = (0, 2000, 1)
	for i in range(n):
		l.append(list(map(int, input().split())))
	l.sort()
	for k in l:
		if k[0] > r:
			c += 1
			(a, r) = k
		else:
			a = k[0]
			r = min(r, k[1])
	print(c)


def solve(intervals):
	intervals.sort(key=lambda x: x[1])
	cnt = 0
	stack = [intervals[0]]
	for i in range(1, len(intervals)):
		curr = intervals[i]
		if stack and curr[0] <= stack[-1][-1]:
			(ps, pe) = stack.pop()
			stack.append([max(ps, curr[0]), min(pe, curr[-1])])
		else:
			stack.append(curr)
	return len(stack)
for _ in range(int(input())):
	n = int(input())
	temp = []
	while n:
		temp.append(list(map(lambda x: int(x), input().split())))
		n -= 1
	print(solve(temp))


for _ in range(int(input())):
	k = []
	for _ in range(int(input())):
		k.append([int(i) for i in input().split()])
	k = sorted(k)
	last_val = k[0][1]
	count = 1
	for i in range(1, len(k)):
		if k[i][0] <= last_val:
			if k[i][1] < last_val:
				last_val = k[i][1]
		else:
			first_val = k[i][0]
			last_val = k[i][1]
			count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		(a, b) = map(int, input().split())
		l.append((a, b))
	l.sort(key=lambda x: x[1])
	max_l = l[0][1]
	final_count = 1
	for ind in range(1, n):
		if l[ind][0] > max_l:
			final_count += 1
			max_l = l[ind][1]
	print(final_count)


t = int(input())
while t:
	n = int(input())
	kingdoms = []
	for i in range(n):
		kingdoms.append(list(map(int, input().split())))
	kingdoms.sort(key=lambda x: x[1])
	curr = 0
	nex = 1
	bombs = 0
	while curr < n:
		while kingdoms[nex][0] <= kingdoms[curr][1]:
			nex += 1
			if nex == n:
				break
		bombs += 1
		if nex == n:
			break
		curr = nex
		nex += 1
		if nex == n:
			bombs += 1
			break
	print(bombs)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		(a, b) = map(int, input().split())
		l.append([a, b])
	l.sort()
	s = l[0][0]
	e = l[0][1]
	b = 0
	for i in range(1, n):
		if l[i][0] <= e:
			s = l[i][0]
			if l[i][1] <= e:
				e = l[i][1]
		else:
			b += 1
			s = l[i][0]
			e = l[i][1]
	print(b + 1)


t = int(input())
for i in range(t):
	n = int(input())
	a = []
	for j in range(n):
		l = list(map(int, input().split()))
		a.append(l)
	a.sort()
	b = 0
	c = 0
	while c < n:
		b += 1
		x = a[c][0]
		y = a[c][1]
		j = c + 1
		while j < n:
			if y >= a[j][0]:
				x = a[j][0]
				if a[j][1] < y:
					y = a[j][1]
				j += 1
			else:
				break
		c = j
	print(b)


def main():
	for _ in range(int(input())):
		kingdoms = sorted([[int(a) for a in input().split(' ')] for _ in range(int(input()))])
		i = kingdoms[0][0]
		j = kingdoms[0][-1]
		bombs = 1
		for a in kingdoms[1:]:
			if a[0] > j:
				i = a[0]
				j = a[1]
				bombs += 1
			else:
				j = a[1] if a[1] < j else j
		print(bombs)
main()