#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
struct Node
{
    ll x , t;
}a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    int t; cin >> t;
    while (t--){
        int n; cin >> n;
        for (int i = 1 ; i <= n ; i++){
            cin >> a[i].t >> a[i].x;
        }
        n++;
        a[n].t = 1e11 , a[n].x = a[n - 1].x;
        ll ans = 0 , ti = a[1].t , pos = 0 , np , nti , l , r;
        ll last = 0;
        for (int i = 1 ; i <= n ; ){
            nti = ti + abs(a[last].x - a[i].x);
            last = i;
            int j;
            for (j = i + 1 ; j <= n ; j++){
                if (a[j].t >= nti) {
                    np = a[i].x;
                    l = min(pos , np) , r = max(pos , np);
                    if (l <= a[j - 1].x && a[j - 1].x <= r) ans++;
                    pos = np;
                    break;
                }
                np = pos;
                if (pos < a[i].x) np += a[j].t - a[j - 1].t;
                else np -= a[j].t - a[j - 1].t;
                l = min(pos , np) , r = max(pos , np);
                if (l <= a[j - 1].x && a[j - 1].x <= r) ans++;
                pos = np;
            }
            i = j;
            ti = a[i].t;
        }
        cout << ans << endl;
    }
    return 0;
}

/*
8
5
1 -4
4 -7
6 -1
7 -3
8 -7

*/
