#include<algorithm>
#include<cstdio>
#define int long long
const int maxn=1e5+5;
const int inf=1073741823000000;
struct order{
	int tim;
	int plc;
	/*friend bool operator<(order now,order oth){
		return now.tim<oth.tim;
	}
	friend bool operator>(order now,order oth){
		return now.tim>oth.tim;
	}*/ 
}ord[maxn];
int t;
int n;
//int ncnt,ntim,nplc,nans;
//int ti[maxn];
//bool ok[maxn];
/*int query(int tim){
	return std::lower_bound(ti+1,ti+n+1,tim)-ti;
}*/
signed main(){
	scanf("%lld",&t);
	for(int wc=1;wc<=t;wc++){
		scanf("%lld",&n);
		for(int i=1;i<=n;i++)scanf("%lld%lld",&ord[i].tim,&ord[i].plc);
		ord[n+1].tim=inf;
		int down_lim=0,up_lim=0,from=0,to=0;
		int ans=0;
		for(int i=1;i<=n;i++){
			if(ord[i].tim>=up_lim){
				from=to,to=ord[i].plc;
				down_lim=ord[i].tim,up_lim=ord[i].tim+abs(from-to);
				if(up_lim<=ord[i+1].tim){
//					puts("sto");
					ans++;
				}
			}
			else{
				double mov=1.0*(to-from)/(up_lim-down_lim);
				int down_now=(int)(from+mov*1.0*(ord[i].tim-down_lim));
				int up_now=(int)(from+mov*1.0*(std::min(ord[i+1].tim-down_lim,up_lim-down_lim)));
				if(down_now>up_now)std::swap(down_now,up_now);
				if(down_now<=ord[i].plc&&ord[i].plc<=up_now){
					ans++;
//					puts("orz");
				}
			}
//			printf("l=%lld,r=%lld,from=%lld,to=%lld,ans=%lld\n",down_lim,up_lim,from,to,ans);
		}
		printf("%d\n",ans);
		/*while(ntim<=ord[n].tim&&ncnt<=n){
			ncnt=query(ntim);
//			printf("ncnt=%d\n",ncnt);
			int gplc=ord[ncnt].plc;
			int gtim=abs(gplc-nplc)+ntim;
//			if(gtim>ord[n].tim)break;
			if(gplc==nplc){
				ntim=ord[ncnt+1].tim;
				nplc=ord[ncnt+1].plc;
				printf("%d=true\n",ncnt);
				ok[ncnt]=true;
				ncnt++;
				continue;
			}
			int mov=(gplc-nplc)/abs(gplc-nplc);
			int gcnt=query(gtim);
			printf("ncnt=%d,nans=%d,nplc=%d,ntim=%d\n",ncnt,nans,nplc,ntim);
			printf("mov=%d,gplc=%d,gtim=%d,gcnt=%d\n",mov,gplc,gtim,gcnt);
			if(ncnt==gcnt){
				puts("same,orz");
				int ktim=std::min(gtim,ord[ncnt].tim)-ntim;
				printf("ktim=%d\n",ktim);
				if((nplc+mov*ktim>=ord[ncnt].plc&&ord[ncnt].plc>=nplc)||(nplc>=ord[ncnt].plc&&ord[ncnt].plc>=nplc+mov*ktim)){
					ok[ncnt]=true;
					printf("%d=true\n",ncnt);
				}
				ntim=ord[ncnt+1].tim;
//				nplc=(gplc==ord[ncnt].plc?ord[ncnt].plc:gplc);
				ncnt++;
				continue;
			}
			if((nplc+mov*(std::min(gtim,ord[ncnt+1].tim)-ntim)>=ord[ncnt].plc&&ord[ncnt].plc>=nplc)||
				(nplc>=ord[ncnt].plc&&ord[ncnt].plc>=nplc+mov*(std::min(gtim,ord[ncnt+1].tim)-ntim))){
				puts("orz"); 
				ok[ncnt]=true;
				printf("%d=true\n",ncnt);
			}
			for(int i=ncnt+1;i<=gcnt-1;i++){
				int qtim=ord[i].tim,htim=std::min(ord[i+1].tim,gtim);
				int dplc=mov*(qtim-ntim)+nplc,uplc=mov*(htim-ntim)+nplc;
				printf("qtim=%d,htim=%d\n",qtim,htim);
				if(((ord[i].plc>=gplc+(ord[i].tim-ntim)*mov&&ord[i].plc<=nplc))||((ord[i].plc>=nplc+(ord[i].tim-ntim)*mov&&ord[i].plc<=gplc))
					(dplc>=ord[i].plc&&ord[i].plc>=uplc)||(uplc>=ord[i].plc&&ord[i].plc>=dplc)){
						printf("dplc=%d,uplc=%d,i=%d,ord[i].plc=%d\n",dplc,uplc,i,ord[i].plc);
						ok[i]=true;
						printf("%d=true\n",ncnt);
						printf("orz,nans=%d\n",nans);
					}
			}
			ntim=gtim;
			nplc=gplc;
		}*/
//		puts("ok");
		/*int dtim=0;
		while(ncnt<=n&&dtim<=ord[n].tim){
//			puts("orz");
			int need=abs(ord[ncnt].plc-nplc);
//			printf("need=%d\n",need);
			dtim=ntim+need;
//			printf("dtim=%d\n",dtim);
			if(dtim<=ord[ncnt+1].tim){
//				printf("%d=true\n",ncnt);
				ok[ncnt]=true;
			}
//			if(dtim
			int gcnt=query(ntim+need);
			int gtim=ord[gcnt].tim;
			int gplc=ord[ncnt].plc;
			if(gplc==nplc){
//				printf("%d=true\n",ncnt);
				ok[ncnt]=true;
				ncnt++;
				ntim=ord[ncnt].tim;
				continue;
			}
			if(gcnt==ncnt){
				ntim=ord[ncnt].tim;
				if(ntim<=ord[n].tim)continue;
				else break;
			}
			int mov=(gplc-nplc)/abs(gplc-nplc);
//			printf("ncnt=%d,nans=%d,nplc=%d,ntim=%d\n",ncnt,nans,nplc,ntim);
//			printf("mov=%d,gplc=%d,gtim=%d,gcnt=%d\n",mov,gplc,gtim,gcnt);
//			puts("mov:ok");
			for(int i=ncnt+1;i<=gcnt-1;i++){
				int qtim=ord[i].tim,htim=std::min(ord[i+1].tim,dtim);
				int dplc=mov*(qtim-ntim)+nplc,uplc=mov*(htim-ntim)+nplc;
//				printf("qtim=%d,htim=%d\n",qtim,htim);
				if((dplc>=ord[i].plc&&ord[i].plc>=uplc)||(uplc>=ord[i].plc&&ord[i].plc>=dplc)){
//						printf("dplc=%d,uplc=%d,i=%d,ord[i].plc=%d\n",dplc,uplc,i,ord[i].plc);
						ok[i]=true;
//						printf("%d=true\n",i);
//						printf("orz,nans=%d\n",nans);
					}
				}
			ncnt=gcnt;
			nplc=gplc;
			ntim=gtim;
		}
		for(int i=1;i<=n;i++)if(ok[i]){
//			printf("ok:%d\n",i);
			nans++;
		}
		printf("%d\n",nans);
		for(int i=1;i<=n;i++){
			ord[i].tim=0;
			ord[i].plc=0;
			ti[i]=0;
			ok[i]=false;
		}*/
	}
	return 0;
}
/*
你有一个可以沿着数轴移动的机器人。在0时刻，它位于0点。
有n个命令：在第t_i秒命令机器人去点x_i。机器人收到命令就开始以每秒1个单位的速度向点x_i移动，到达时停止。当机器人移动时，它会忽略你给他的所有其他命令。
如果机器人在[t_i,t_{i+1}]范围内有一个时间点在x点，则成功地调用命令i（在您发出此命令之后，在您发出另一个命令之前，包括两个边界）。
计算成功的命令数。请注意，被忽略的命令可能成功。
*/
/*
1
2
1 1
2 1
*/
### Prompt

Please formulate a Cpp solution to the following problem:

You have a robot that can move along a number line. At time moment 0 it stands at point 0.

You give n commands to the robot: at time t_i seconds you command the robot to go to point x_i. Whenever the robot receives a command, it starts moving towards the point x_i with the speed of 1 unit per second, and he stops when he reaches that point. However, while the robot is moving, it ignores all the other commands that you give him.

For example, suppose you give three commands to the robot: at time 1 move to point 5, at time 3 move to point 0 and at time 6 move to point 4. Then the robot stands at 0 until time 1, then starts moving towards 5, ignores the second command, reaches 5 at time 6 and immediately starts moving to 4 to execute the third command. At time 7 it reaches 4 and stops there.

You call the command i successful, if there is a time moment in the range [t_i, t_{i + 1}] (i. e. after you give this command and before you give another one, both bounds inclusive; we consider t_{n + 1} = +∞) when the robot is at point x_i. Count the number of successful commands. Note that it is possible that an ignored command is successful.

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. The next lines describe the test cases.

The first line of a test case contains a single integer n (1 ≤ n ≤ 10^5) — the number of commands.

The next n lines describe the commands. The i-th of these lines contains two integers t_i and x_i (1 ≤ t_i ≤ 10^9, -10^9 ≤ x_i ≤ 10^9) — the time and the point of the i-th command.

The commands are ordered by time, that is, t_i < t_{i + 1} for all possible i.

The sum of n over test cases does not exceed 10^5.

Output

For each testcase output a single integer — the number of successful commands.

Example

Input


8
3
1 5
3 0
6 4
3
1 5
2 4
10 -5
5
2 -5
3 1
4 1
5 1
6 1
4
3 3
5 -3
9 2
12 0
8
1 1
2 -6
7 2
8 3
12 -9
14 2
18 -1
23 9
5
1 -4
4 -7
6 -1
7 -3
8 -7
2
1 2
2 -2
6
3 10
5 5
8 0
12 -4
14 -7
19 -5


Output


1
2
0
2
1
1
0
2

Note

The movements of the robot in the first test case are described in the problem statement. Only the last command is successful.

In the second test case the second command is successful: the robot passes through target point 4 at time 5. Also, the last command is eventually successful.

In the third test case no command is successful, and the robot stops at -5 at time moment 7.

Here are the 0-indexed sequences of the positions of the robot in each second for each testcase of the example. After the cut all the positions are equal to the last one: 

  1. [0, 0, 1, 2, 3, 4, 5, 4, 4, ...] 
  2. [0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -5, ...] 
  3. [0, 0, 0, -1, -2, -3, -4, -5, -5, ...] 
  4. [0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 2, 2, 2, 1, 0, 0, ...] 
  5. [0, 0, 1, 0, -1, -2, -3, -4, -5, -6, -6, -6, -6, -7, -8, -9, -9, -9, -9, -8, -7, -6, -5, -4, -3, -2, -1, -1, ...] 
  6. [0, 0, -1, -2, -3, -4, -4, -3, -2, -1, -1, ...] 
  7. [0, 0, 1, 2, 2, ...] 
  8. [0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -7, ...] 

### Response

```cpp
#include<algorithm>
#include<cstdio>
#define int long long
const int maxn=1e5+5;
const int inf=1073741823000000;
struct order{
	int tim;
	int plc;
	/*friend bool operator<(order now,order oth){
		return now.tim<oth.tim;
	}
	friend bool operator>(order now,order oth){
		return now.tim>oth.tim;
	}*/ 
}ord[maxn];
int t;
int n;
//int ncnt,ntim,nplc,nans;
//int ti[maxn];
//bool ok[maxn];
/*int query(int tim){
	return std::lower_bound(ti+1,ti+n+1,tim)-ti;
}*/
signed main(){
	scanf("%lld",&t);
	for(int wc=1;wc<=t;wc++){
		scanf("%lld",&n);
		for(int i=1;i<=n;i++)scanf("%lld%lld",&ord[i].tim,&ord[i].plc);
		ord[n+1].tim=inf;
		int down_lim=0,up_lim=0,from=0,to=0;
		int ans=0;
		for(int i=1;i<=n;i++){
			if(ord[i].tim>=up_lim){
				from=to,to=ord[i].plc;
				down_lim=ord[i].tim,up_lim=ord[i].tim+abs(from-to);
				if(up_lim<=ord[i+1].tim){
//					puts("sto");
					ans++;
				}
			}
			else{
				double mov=1.0*(to-from)/(up_lim-down_lim);
				int down_now=(int)(from+mov*1.0*(ord[i].tim-down_lim));
				int up_now=(int)(from+mov*1.0*(std::min(ord[i+1].tim-down_lim,up_lim-down_lim)));
				if(down_now>up_now)std::swap(down_now,up_now);
				if(down_now<=ord[i].plc&&ord[i].plc<=up_now){
					ans++;
//					puts("orz");
				}
			}
//			printf("l=%lld,r=%lld,from=%lld,to=%lld,ans=%lld\n",down_lim,up_lim,from,to,ans);
		}
		printf("%d\n",ans);
		/*while(ntim<=ord[n].tim&&ncnt<=n){
			ncnt=query(ntim);
//			printf("ncnt=%d\n",ncnt);
			int gplc=ord[ncnt].plc;
			int gtim=abs(gplc-nplc)+ntim;
//			if(gtim>ord[n].tim)break;
			if(gplc==nplc){
				ntim=ord[ncnt+1].tim;
				nplc=ord[ncnt+1].plc;
				printf("%d=true\n",ncnt);
				ok[ncnt]=true;
				ncnt++;
				continue;
			}
			int mov=(gplc-nplc)/abs(gplc-nplc);
			int gcnt=query(gtim);
			printf("ncnt=%d,nans=%d,nplc=%d,ntim=%d\n",ncnt,nans,nplc,ntim);
			printf("mov=%d,gplc=%d,gtim=%d,gcnt=%d\n",mov,gplc,gtim,gcnt);
			if(ncnt==gcnt){
				puts("same,orz");
				int ktim=std::min(gtim,ord[ncnt].tim)-ntim;
				printf("ktim=%d\n",ktim);
				if((nplc+mov*ktim>=ord[ncnt].plc&&ord[ncnt].plc>=nplc)||(nplc>=ord[ncnt].plc&&ord[ncnt].plc>=nplc+mov*ktim)){
					ok[ncnt]=true;
					printf("%d=true\n",ncnt);
				}
				ntim=ord[ncnt+1].tim;
//				nplc=(gplc==ord[ncnt].plc?ord[ncnt].plc:gplc);
				ncnt++;
				continue;
			}
			if((nplc+mov*(std::min(gtim,ord[ncnt+1].tim)-ntim)>=ord[ncnt].plc&&ord[ncnt].plc>=nplc)||
				(nplc>=ord[ncnt].plc&&ord[ncnt].plc>=nplc+mov*(std::min(gtim,ord[ncnt+1].tim)-ntim))){
				puts("orz"); 
				ok[ncnt]=true;
				printf("%d=true\n",ncnt);
			}
			for(int i=ncnt+1;i<=gcnt-1;i++){
				int qtim=ord[i].tim,htim=std::min(ord[i+1].tim,gtim);
				int dplc=mov*(qtim-ntim)+nplc,uplc=mov*(htim-ntim)+nplc;
				printf("qtim=%d,htim=%d\n",qtim,htim);
				if(((ord[i].plc>=gplc+(ord[i].tim-ntim)*mov&&ord[i].plc<=nplc))||((ord[i].plc>=nplc+(ord[i].tim-ntim)*mov&&ord[i].plc<=gplc))
					(dplc>=ord[i].plc&&ord[i].plc>=uplc)||(uplc>=ord[i].plc&&ord[i].plc>=dplc)){
						printf("dplc=%d,uplc=%d,i=%d,ord[i].plc=%d\n",dplc,uplc,i,ord[i].plc);
						ok[i]=true;
						printf("%d=true\n",ncnt);
						printf("orz,nans=%d\n",nans);
					}
			}
			ntim=gtim;
			nplc=gplc;
		}*/
//		puts("ok");
		/*int dtim=0;
		while(ncnt<=n&&dtim<=ord[n].tim){
//			puts("orz");
			int need=abs(ord[ncnt].plc-nplc);
//			printf("need=%d\n",need);
			dtim=ntim+need;
//			printf("dtim=%d\n",dtim);
			if(dtim<=ord[ncnt+1].tim){
//				printf("%d=true\n",ncnt);
				ok[ncnt]=true;
			}
//			if(dtim
			int gcnt=query(ntim+need);
			int gtim=ord[gcnt].tim;
			int gplc=ord[ncnt].plc;
			if(gplc==nplc){
//				printf("%d=true\n",ncnt);
				ok[ncnt]=true;
				ncnt++;
				ntim=ord[ncnt].tim;
				continue;
			}
			if(gcnt==ncnt){
				ntim=ord[ncnt].tim;
				if(ntim<=ord[n].tim)continue;
				else break;
			}
			int mov=(gplc-nplc)/abs(gplc-nplc);
//			printf("ncnt=%d,nans=%d,nplc=%d,ntim=%d\n",ncnt,nans,nplc,ntim);
//			printf("mov=%d,gplc=%d,gtim=%d,gcnt=%d\n",mov,gplc,gtim,gcnt);
//			puts("mov:ok");
			for(int i=ncnt+1;i<=gcnt-1;i++){
				int qtim=ord[i].tim,htim=std::min(ord[i+1].tim,dtim);
				int dplc=mov*(qtim-ntim)+nplc,uplc=mov*(htim-ntim)+nplc;
//				printf("qtim=%d,htim=%d\n",qtim,htim);
				if((dplc>=ord[i].plc&&ord[i].plc>=uplc)||(uplc>=ord[i].plc&&ord[i].plc>=dplc)){
//						printf("dplc=%d,uplc=%d,i=%d,ord[i].plc=%d\n",dplc,uplc,i,ord[i].plc);
						ok[i]=true;
//						printf("%d=true\n",i);
//						printf("orz,nans=%d\n",nans);
					}
				}
			ncnt=gcnt;
			nplc=gplc;
			ntim=gtim;
		}
		for(int i=1;i<=n;i++)if(ok[i]){
//			printf("ok:%d\n",i);
			nans++;
		}
		printf("%d\n",nans);
		for(int i=1;i<=n;i++){
			ord[i].tim=0;
			ord[i].plc=0;
			ti[i]=0;
			ok[i]=false;
		}*/
	}
	return 0;
}
/*
你有一个可以沿着数轴移动的机器人。在0时刻，它位于0点。
有n个命令：在第t_i秒命令机器人去点x_i。机器人收到命令就开始以每秒1个单位的速度向点x_i移动，到达时停止。当机器人移动时，它会忽略你给他的所有其他命令。
如果机器人在[t_i,t_{i+1}]范围内有一个时间点在x点，则成功地调用命令i（在您发出此命令之后，在您发出另一个命令之前，包括两个边界）。
计算成功的命令数。请注意，被忽略的命令可能成功。
*/
/*
1
2
1 1
2 1
*/
```