#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>

using namespace std;

vector<int> f(vector<int> v, int n) {
	sort(v.begin(), v.end());
	vector<int> res;
	int c = 0;
	for (int i=0, ind=0;ind<n;++ind) {
		c++;
		if (i < (int)v.size() && v[i] <= 2 * ind) {
			i++;
			res.push_back(c);
		}
	}
	return res;
}

void solve(int test_ind){
	int a, b, n;
	cin >> n >> a >> b;
	map<int, vector<int> > mp;
	for (int i=0;i<n;++i) {
		int x, y;
		cin >> x >> y;
		--x;--y;
		mp[x].push_back(y);
	}
	vector<int> cur(n + 1);
	for (int i=0;i<=n;++i) cur[i] = i;
	for (auto &pr: mp) {
		vector<int> v = f(pr.second, n);
		vector<int> nxt = cur;
		for (int j=0;j<=n;++j) {
			for (int i=0;i<(int)v.size();++i) {
				int j1 = v[i] + j;
				if (j1 > n) break;
				nxt[j1] = min(nxt[j1], cur[j] + v[i] - (i + 1));
			}
		}
		cur = move(nxt);
	}
	cout << cur[n] << endl;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int t=1;
	cin >> t;
	for(int i=0;i<t;i++){
		solve(i);
	}
	return 0;
}
