
#include <bits/stdc++.h>
#define ll signed long long
using namespace std;




int main()
{

    ofstream fout;
    fout.open("output.txt");
    ll t, n;
    cin >> t;
    while (t--)
    {
        cin >> n;
        vector<pair<ll, ll> > v(n+1);
        for (int i = 0; i < n; i++)
        {
            cin >> v[i].first >> v[i].second;
        }

        v[n].first = 1000000000000000;

        ll currentpos = 0, movementdirection, endmovetime = 0, ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (v[i].first >= endmovetime)
            {
                if (i!=0)
                {
                    currentpos += (endmovetime-v[i-1].first)*movementdirection;
                }

               // cout << currentpos << "\n";
                if (v[i].second > currentpos)
                {
                    movementdirection = 1;
                }
                else
                {
                    movementdirection = -1;
                }
                endmovetime = v[i].first + abs(currentpos-v[i].second);


                ll startpos = currentpos, endpos = (min(endmovetime, v[i+1].first)-v[i].first)*movementdirection + currentpos;
                if (startpos <= endpos)
                {
                    if (v[i].second >= startpos && v[i].second <= endpos)
                    {
                        ans++;
                    }

                }
                else
                {
                    if (v[i].second >= endpos && v[i].second <= startpos)
                    {
                        ans++;
                    }
                }
            }
            else
            {
                currentpos += (v[i].first - v[i-1].first)*movementdirection;

               // cout << currentpos << "\n";

                ll startpos = currentpos, endpos = (min(endmovetime, v[i+1].first)-v[i].first)*movementdirection + currentpos;
                if (startpos <= endpos)
                {
                    if (v[i].second >= startpos && v[i].second <= endpos)
                    {
                        ans++;
                    }

                }
                else
                {
                    if (v[i].second >= endpos && v[i].second <= startpos)
                    {
                        ans++;
                    }
                }
            }
        }

        cout << ans << "\n";
    }

    fout.close();
}