#include <stdio.h> int main (void) { int m,n,s,i,j,k,l,t,a[5005],b[5005]; scanf("%d",&m); while(m--&&scanf("%d",&n)) { for(i=0;i<n;i++) scanf("%d%d",&a[i],&b[i]); for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) { if(a[i]>a[j]||(a[i]==a[j]&&b[i]>b[j])) { t=a[i];a[i]=a[k];a[j]=t; t=b[i];b[i]=b[j];b[j]=t; } } s=1; for(i=0;i<n-1;i++) { if(a[i]==0) continue; k=a[i];l=b[i]; for(j=i+1;j<n;j++) { if(a[j]==0) continue; if(k<=a[j]&&l<=b[j]) { k=a[j]; l=b[j]; a[i]=0; } } s++; } printf("%d\n",s); } return 0; }