#include<iostream>
#include<bits/stdc++.h>
#include<stdio.h>

using namespace std;
/*
int main(){
	int n;
	cin>>n;
	while(n--){
		int a,b,c;
		cin>>a>>b>>c;
		//һ�����6+3��Ѫ 
		int mins = min(a,min(b,c));
		int cnt = a+b+c;
		if(cnt%9 == 0 && cnt/9 < mins+1) {
			cout<<"YES";
		} else{
			cout<<"NO";
		}
		cout<<endl;
	}
	
	return 0;
} */
/*
//typedef unsigned long long ull;
int arr[1000];
//int arrb[1000];

int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
//		ull s=0;
		int b;
		for(int i=0;i<n;i++) {
			b=1;
			cin>>arr[i];
//			s+=arr[i];
			while(2*b<=arr[i]) b*=2;
			cout<<b<<" ";
		}
		cout<<endl;
	}
	return 0;
}
*/
typedef long long ll;
ll arr[10000001];
ll arrx[10000001];
int main(){
	int t;
	cin>>t;
	
	while(t--){
		int n;
		cin>>n;
		for(int i=0;i<n;i++) cin>>arr[i]>>arrx[i];
		arr[n]=1e10;
		int id_x=0;
		ll now=0,next=0;
		int flag=0,cnt=0;
		while(id_x<n){
			ll y=next;
			ll b=arr[id_x];
			now=arr[id_x]+abs(arrx[id_x]-next);
			if(arrx[id_x]<next) flag=-1;
			else flag=1;
			next=arrx[id_x];
			int k=id_x+1;
			while(arr[k]<now&&k<n) k++;
			for(int i=id_x;i<k;i++){
				ll stx=y+flag*(min(arr[i],now)-b);
				ll sdx=y+flag*(min(arr[i+1],now)-b);
				if(arrx[i]>=min(stx,sdx)&&arrx[i]<=max(stx,sdx)) cnt++;
			}
			id_x=k;
		}
		cout<<cnt<<endl;
	}
	
}
