


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <cstdio>
#include <map>
#include <queue>
#include <ctime>
#include <iomanip>
#include <stack>
#include <assert.h>
#include <unordered_map>

using namespace std;

#define F first
#define ll long long
#define S second
#define ld long double
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define PI acos(-1)

ll a, b, c, d, e, fl, maxn, cnt, k, s;
vector <ll> ar;



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t = 1;
    cin >> t;
    while(t--)
    {
        cin >> a;
        ll last_time = -1;
        ll last_pos = 0;
        ll nap = 0;
        ll pos = 0;
        ll ans = 0;
        ll lst = 0, lsp = 0;
        queue <pair <ll, ll> > q;
        rep(i, a + 1)
        {
            ll p, p1;
            if (i != a)
                cin >> p >> p1;
            else
                p = (ll)1e15;
            if (!q.empty())
            {
                pair <ll, ll> pp = q.front();
                q.pop();
                ll st = last_pos + nap * (pp.F - last_time);
                ll fin = last_pos + nap * (min(p, lst) - last_time);
                //cout << i << " " << st << " " << fin << " " << pp.S << '\n';
                if (min(st, fin) <= pp.S && max(st, fin) >= pp.S)
                    ++ans;
            }
            if (i == a)
                continue;
            if (p >= lst)
            {
                last_time = p;
                last_pos = lsp;
                lsp = p1;
                lst = abs(last_pos - p1) + p;
                if (last_pos > p1)
                    nap = -1;
                else
                    nap = 1;
            }
            q.push({p, p1});
        }
        cout << ans << '\n';
    }
}
