N one dimensional kingdoms are represented as intervals of the form [ai , bi] 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 ai and bi.



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

Constraints
Example
Input:
1
3
1 3
2 5
6 9

Output:
2

Explanation
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 .
''' You misunderstood the problem as is.
    You can't chain the bombs which is what your code assumes.
'''
def wrong_version():
  T = int(raw_input())
  for _ in xrange(T):
    N = int(raw_input())
    inp_tup_list = []
    for _ in xrange(N):
      inp_tup_list.append(tuple(map(int, raw_input().split())))
    sorted(inp_tup_list, key=lambda x: x[0])
    l, u = -1, -1
    count = 0
    for (x, y) in inp_tup_list:
      if x > u:
        count += 1
        u = x
      if y > u:
        u = y
    print count

if __name__ == '__main__':
  T = int(raw_input())
  for _ in xrange(T):
    N = int(raw_input())
    inp_tup_list = []
    for _ in xrange(N):
      inp_tup_list.append(tuple(map(int, raw_input().split())))
    inp_tup_list.sort(key=lambda x: x[0])

    l, u = -1, -1
    count = 0
    for (x, y) in inp_tup_list:
      if x > u:
        l, u = x, y
        count += 1
      elif x == u:
        l = x
        if y == u:
          l, u = x, y
      elif x >= l:
        l = x
        if y < u:
          u = y

    print count