// Original C++ solution (slower):
#include <iostream>

#include <cstdlib>

#include <cstdio>

#include <cstring>

#include <algorithm>



#include <vector>



using namespace std;





typedef long long LL;





typedef pair <int, int> pr;





const int N = 2e5 + 10;



const int INF = 2e9;





const LL mod = 1e9 + 7;





inline LL power(LL a, LL n, LL mod)

{

	LL Ans = 1;

	while (n)

	{

		if (n & 1) Ans = Ans * a % mod;

		a = a * a % mod;

		n >>= 1;

	}

	return Ans;

}





namespace ufs

{

	int parent[N];



	void init(int n) { for (int i = 1; i <= n; i++) parent[i] = i; }



	inline int findrt(int x) { return parent[x] == x ? x : parent[x] = findrt(parent[x]); }



	void merge(int x, int y)

	{

		x = findrt(x), y = findrt(y);

		parent[x] = y;

	}

}





int col[N], w[N];

int n, X, Y;



pr minv[N];

vector <int> vec[N];

int cnt[N];





LL fac[N], ifac[N];



inline LL calc(int n, int m) { return n < m ? 0 : fac[n] * ifac[m] % mod * ifac[n-m] % mod; }





int main()

{

	cin >> n >> X >> Y;

	

	fac[0] = 1;

	for (int i = 1; i <= n; i++) fac[i] = fac[i-1] * i % mod;

	ifac[n] = power(fac[n], mod-2, mod);

	for (int i = n-1; i >= 0; i--) ifac[i] = ifac[i+1] * (i+1) % mod;

	

	int maxc = 0;

	for (int i = 1; i <= n; i++)

	{

		scanf("%d %d", &col[i], &w[i]);

		maxc = max(maxc, col[i]);

	}

	for (int i = 1; i <= maxc; i++) minv[i] = make_pair(INF, INF);

	

	for (int i = 1; i <= n; i++)

	{

		minv[col[i]] = min(minv[col[i]], make_pair(w[i], i));

		vec[col[i]].push_back(i);

	}

	

	ufs::init(n);

	

	for (int i = 1; i <= maxc; i++)

	{

		for (auto id : vec[i])

			if (w[id] + minv[i].first <= X)

				ufs::merge(id, minv[i].second);

	}

	

	pr mn = make_pair(INF, INF), mn2 = make_pair(INF, INF);

	for (int i = 1; i <= n; i++)

	{

		pr tmp = make_pair(w[i], i);

		mn = min(mn, tmp);

	}

	for (int i = 1; i <= n; i++)

	{

		pr tmp = make_pair(w[i], i);

		if (col[i] != col[mn.second])

			mn2 = min(mn2, tmp);

	}

	

	for (int i = 1; i <= n; i++)

		if (col[mn.second] != col[i] && mn.first + w[i] <= Y)

			ufs::merge(mn.second, i);

		else if (mn2.first != INF && col[mn2.second] != col[i] && mn2.first + w[i] <= Y)

			ufs::merge(mn2.second, i);

	

	for (int i = 1; i <= n; i++)

		if (ufs::findrt(i) == ufs::findrt(mn.second))

			cnt[col[i]]++;

	

	int all = 0;

	for (int i = 1; i <= maxc; i++)

		all += cnt[i];

	

	LL Ans = 1;

	for (int i = 1; i <= maxc; i++)

		if (cnt[i])

		{

			Ans = Ans * calc(all, cnt[i]) % mod;

			all -= cnt[i];

		}

	

	printf("%lld\n", Ans);

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include <algorithm>

#include <cstdio>

#include <cstring>



typedef long long LL;



const int MAXN = 200000;

const int MOD = 1000000007;

const int INF = 1000000001;



int N, X, Y, C[MAXN + 5], W[MAXN + 5];



int Min[MAXN + 5], Cnt[MAXN + 5];



int Fac[MAXN + 5], Inv[MAXN + 5];



int Pow(int x, int y) {

	int ret = 1;

	while (y) {

		if (y & 1)

			ret = (LL)ret * x % MOD;

		y >>= 1;

		x = (LL)x * x % MOD;

	}

	return ret;

}



int main() {

	scanf("%d%d%d", &N, &X, &Y);

	Fac[0] = 1;

	for (int i = 1; i <= N; i++)

		Fac[i] = (LL)Fac[i - 1] * i % MOD;

	Inv[N] = Pow(Fac[N], MOD - 2);

	for (int i = N - 1; i >= 0; i--)

		Inv[i] = (LL)Inv[i + 1] * (i + 1) % MOD;

	for (int i = 0; i <= N; i++)

		Min[i] = INF;

	for (int i = 1; i <= N; i++) {

		scanf("%d%d", &C[i], &W[i]);

		Cnt[C[i]]++;

		Min[C[i]] = std::min(Min[C[i]], W[i]);

	}

	int fir = std::min_element(Min + 1, Min + N + 1) - Min, sec = 0;

	for (int i = 1; i <= N; i++)

		if (i != fir && Min[i] < Min[sec])

			sec = i;

	for (int i = 1; i <= N; i++) { // 对于每个球

		if (W[i] != Min[C[i]] && W[i] + Min[C[i]] <= X) // 内部就可以交换

			continue;

		if (C[i] != fir && W[i] + Min[fir] <= Y) // 可交换出去

			continue;

		if (C[i] == fir && W[i] + Min[sec] <= Y) // 可交换出去

			continue;

		Cnt[C[i]]--; // 该球无法移动

	}

	int tot = 0, Ans = 1;

	for (int i = 1; i <= N; i++) // 合并每个颜色的连通块

		if (Min[i] + Min[fir] <= Y)

			Ans = (LL)Ans * Inv[Cnt[i]] % MOD, tot += Cnt[i];

	printf("%d", (LL)Ans * Fac[tot] % MOD);

}

// Fastest known solution for this problem: