#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
pair<int, int> a[N], b[N];
int main()
{
    multiset<int> s;
    int T, n;
    scanf("%d", &T);
    while (T--)
    {
        s.clear();
        scanf("%d", &n);
        for (int i = 0; i < n; i++)
            scanf("%d%d", &a[i].first, &a[i].second);
        for (int i = 0; i < n; i++)
            scanf("%d%d", &b[i].first, &b[i].second);
        sort(a, a + n), sort(b, b + n);
        int cnt = 0;
        for (int i = 0, j = 0; i < n; i++)
        {
            while (j < n && a[i].first >= b[j].first)
                s.insert(b[j++].second);
            auto ite = s.upper_bound(a[i].second);
            if (ite != s.begin()) s.erase(--ite), cnt++;
        }
        printf("%d\n", cnt);
    }
    return 0;
}
