#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)





template<int um> struct UF {
	vector<int> par; UF() { clear(); }
	int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
	void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) par[x] = y; }
	void clear() { par = vector<int>(um, 0); rep(i, 0, um) par[i] = i; }
};
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
int mul(int x, int y) { return 1LL * x * y % mod; }
int modpow(int a, long long b) {
	int ret = 1;
	while (b > 0) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; }
	return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
int fac[201010], ifac[201010];
void initfac() {
	fac[0] = ifac[0] = 1;
	rep(i, 1, 201010) fac[i] = 1LL * i * fac[i - 1] % mod;
	rep(i, 1, 201010) ifac[i] = modinv(fac[i]);
}
//-----------------------------------------------------------------------------------
int N, X, Y, C[201010], W[201010];
UF<201010> uf;
void naive_merge() {
	rep(a, 0, N) rep(b, a + 1, N) {
		if (C[a] == C[b] && W[a] + W[b] <= X) uf(a, b);
		if (C[a] != C[b] && W[a] + W[b] <= Y) uf(a, b);
	}
}
//-----------------------------------------------------------------------------------
void optimized_merge() {
	map<int, vector<pair<int, int>>> color;
	rep(i, 0, N) color[C[i]].push_back({ W[i], i });
	for (auto& g : color) sort(g.second.begin(), g.second.end());

	// same color
	for (auto& g : color) {
		auto v = g.second;
		rep(i, 1, v.size()) if (v[0].first + v[i].first <= X) uf(v[0].second, v[i].second);
	}
	
	// different color
	vector<int> order;
	for (auto& g : color) order.push_back(g.first);
	sort(order.begin(), order.end(), [&](int a, int b) {
		return color[a][0].first < color[b][0].first;
	});
	//color[order[0]][0] -> any
	rep(i, 0, N) {
		auto p = color[order[0]][0];
		if (p.first + W[i] <= Y && order[0] != C[i]) uf(p.second, i);
	}
	//color[order[1]][0] -> any
	if (2 <= order.size()) rep(i, 0, N) {
		auto p = color[order[1]][0];
		if (p.first + W[i] <= Y && order[1] != C[i]) uf(p.second, i);
	}
}
//-----------------------------------------------------------------------------------
int count() {
	map<int, vector<int>> group;
	rep(i, 0, N) group[uf[i]].push_back(i);
	//cout << group.size() << endl;

	int res = 1;
	for (auto g : group) {
		auto v = g.second;
		/*printf("{ ");
		for (int i : v) printf("%d ", i);
		printf("}\n");*/

		int com = fac[v.size()];

		map<int, int> cnt;
		for (int i : v) cnt[C[i]]++;
		for (auto p : cnt) com = mul(com, ifac[p.second]);

		res = mul(res, com);
	}

	return res;
}
//-----------------------------------------------------------------------------------
void maketest() {
	random_device rd;
	mt19937 mt(rd());
	uniform_int_distribution<> rand(1, 100);
	uniform_int_distribution<> rand2(1, 100);
	
	N = 20;
	X = rand(mt);
	Y = rand(mt);
	rep(i, 0, N) C[i] = rand2(mt), W[i] = rand2(mt);
}
void printtest() {
	printf("---------------\n");
	printf("%d %d %d\n", N, X, Y);
	rep(i, 0, N) printf("%d %d\n", C[i], W[i]);
	printf("---------------\n");
}
//-----------------------------------------------------------------------------------
int main() {
	initfac();
	cin >> N >> X >> Y;
	rep(i, 0, N) scanf("%d%d", &C[i], &W[i]);

	/*map<int, set<int>> m;
	rep(i, 0, N) m[C[i]].insert(W[i]);
	int idx = 0;
	for (auto p : m) {
		for (int i : p.second) {
			C[idx] = p.first;
			W[idx] = i;
			idx++;
		}
	}
	printtest();*/

	/*naive_merge();
	cout << count() << endl;
	uf.clear();*/
	optimized_merge();
	cout << count() << endl;
	return 0;

	rep(i, 0, 100) {
		maketest();

		uf.clear();
		naive_merge();

		int a = count();

		uf.clear();
		optimized_merge();
		
		int b = count();

		if (a != b) {
			printtest();
			uf.clear();
			naive_merge();
			cout << count() << endl;
			uf.clear();
			optimized_merge();
			cout << count() << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 25352