import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int t=Integer.parseInt(br.readLine());
while(t-->0){
int n=Integer.parseInt(br.readLine());
ArrayList<People> arr=new ArrayList<>();
for(int i=0;i<n;i++){
st=new StringTokenizer(br.readLine());
int a=Integer.parseInt(st.nextToken());
int b=Integer.parseInt(st.nextToken());
arr.add(new People(a,b));
}
Collections.sort(arr);
People now=arr.get(0);
int cnt=1;
for(People p:arr){
if(p.b<now.b){
cnt++;
now=p;
}
}
System.out.println(cnt);
}
}
static class People implements Comparable<People>{
int a,b;
public People(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public int compareTo(People o) {
return this.a!=o.a?this.a-o.a:this.b-o.b;
}
}
}
#그리디