#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

constexpr int P = 1000000007;

vector<int> balls[200001];
int minWeight[200001], connected[200001];
int inv[200001], fac[200001], invFac[200001];

int main() {
	int n, x, y;

	cin >> n >> x >> y;
	memset(minWeight, 0x3f, sizeof minWeight);
	for (int i = 1; i <= n; ++i) {
		int c, w;
		cin >> c >> w;
		balls[c].push_back(w);
		minWeight[c] = min(minWeight[c], w);
	}

	int m1 = 0, m2 = 0;
	for (int i = 1; i <= n; ++i)
		if (minWeight[i] < minWeight[m1]) {
			m2 = m1;
			m1 = i;
		} else if (minWeight[i] < minWeight[m2]) {
			m2 = i;
		}

	int sum = 0;
	for (int i = 1; i <= n; ++i) {
		int cx = 0, cy = 0;
		for (int o: balls[i]) {
			if (minWeight[i] + o <= x) ++cx;
			if ((i != m1 && minWeight[m1] + o <= y) || minWeight[m2] + o <= y) ++cy;
		}
		connected[i] = cy != 0 ? max(cx, cy) : 0;
		sum += connected[i];
	}

	inv[1] = 1;
	for (int i = 2; i <= n; ++i)
		inv[i] = static_cast<long long>(P - P / i) * inv[P % i] % P;
	
	fac[0] = invFac[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i] = static_cast<long long>(fac[i - 1]) * i % P;
		invFac[i] = static_cast<long long>(invFac[i - 1]) * inv[i] % P;
	}

	int ans = fac[sum];
	for (int i = 1; i <= n; ++i)
		ans = static_cast<long long>(ans) * invFac[connected[i]] % P;
	
	cout << ans << endl;

	return 0;
}