#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <random>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << " = "; for (auto xxxx: a) cerr << xxxx << " "; cerr << endl


using namespace std;

#ifdef LOCAL
static struct __timestamper {
    string what;
    __timestamper(const char* what) : what(what){};
    __timestamper(const string& what) : what(what){};
    ~__timestamper(){
        TIMESTAMPf("%s", what.data());
    }
} __TIMESTAMPER("end");
#else
struct __timestamper {};
#endif

typedef long long ll;
typedef long double dbl;

const int MOD = 998244353;

void add(int &x, int y) {
    x += y;
    if (x >= MOD) x -= MOD;
}

int mul(int x, int y) {
    return 1LL * x * y % MOD;
}

int solve(int n, int A, int B, vector<pair<int, int>> c) {
    map<int, vector<int>> mp;
    for (auto o : c) mp[o.first].push_back(o.second);

    const int INF = 1e9;
    vector<int> dp(1, 0);
    for (auto it : mp) {
        auto v = it.second;
        sort(v.begin(), v.end());
        int m = v.size();

        vector<int> ndp(dp.size() + v.size(), INF);
        int add = 0;
        for (int i = 0; i <= (int)v.size(); i++) {
            int rem = (int)v.size() - i;
            // {rem, add}
            for (int j = 0; j < (int)dp.size(); j++) {
                ndp[j + rem] = min(ndp[j + rem], dp[j] + add);
            }

            if (i < (int)v.size()) {
                int min_pos = v[i] / 2 + v[i] % 2;
                add = max(add, min_pos - i);
            }
        }
        dp = ndp;
    }
    int ans = INF;
    for (int i = 0; i <= n; i++) {
        if (dp[i] <= i) {
            ans = min(ans, i);
        }
    }
    return ans;
}

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
#endif

    int T;
    scanf("%d", &T);
    while (T--) {
        int n, A, B;
        scanf("%d%d%d", &n, &A, &B);
        vector<pair<int, int>> c(n);
        for (auto &o : c) {
            scanf("%d%d", &o.first, &o.second);
            o.first--;
            o.second--;
        }

        int ans = solve(n, A, B, c);
        cout << ans << endl;
    }

    return 0;
}