#include <iomanip>
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <set>
#include "queue"
//#include <multiset>
#include <map>
#include <utility>
#include <numeric>
#include "random"
#ifndef __clang__
#include <bits/stdc++.h>
#endif
using namespace std;

#define all(x) (x).begin(), (x).end()

const int mod = 999999001;

void solve() {
    int n, A, B;
    cin >> n >> A >> B;
    vector<int> a(n * 2 + 3, 1e6);
    vector<int> b = a;
    a[n+1] = 0;
    map<int, vector<int>> elba;
    for (int i = 0; i < n; ++i) {
        int ai, bi;
        cin >> ai >> bi;
        elba[ai].push_back(bi);
    }
    for (auto i : elba) {
        vector<int> c = i.second;
        vector<int> stk = {0};
        int ind = 0;
        for (auto j : c) {
            ind++;
            //cerr << j << ' ' << 2 * ind - 1 << endl;
            if (j-(2*ind -1)<=0)
                stk.push_back(max(stk.back(), j-(2*ind -1)));
            else
                stk.push_back(max(stk.back(), (j-(2*ind -1)+1)/2));
        }
        //cout << stk.back() << '\n';
        for (int j = 0; j < b.size(); ++j) {
            b[j] = 1e6;
        }
        for (int j = 0; j < stk.size(); ++j) {
            int bd1 = c.size() - j;
            int bd2 = stk[j];
            int crd = bd2 - bd1;
            //cerr << i.first << ' ' << bd2 << ' ' << bd1 << ' ' << crd << ' ' << min(bd1, bd2) << endl;
            for (int k = 0; k < a.size(); ++k) {
                if (k + crd >= 0 and k + crd < a.size()) {
                    b[k+crd] = min(b[k+crd], a[k]+bd2);
                }
                if (k + crd < 0) {
                    int c1 = -(k+crd);
                    b[0] = min(b[0], a[k] + c1 + bd2);
                }
                if (k + crd >= a.size()) {
                    int t = a.size() - 1;
                    b[t] = min(b[t], a[k] + bd2);
                }
            }
        }
        swap(a, b);
    }
    int res = 1e6;
    for (int i = 0; i < b.size(); ++i) {
        int v1 = max(0, n+1-i);
        int v2 = a[i];
        //cerr << i << ' ' << v1 << ' ' << v2 << endl;
        res = min(res, v1 + v2);
    }
    cout << res << '\n';
}

signed main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}
