#include <bits/stdc++.h>
#define x first
#define y second
#define y1 secondy1
#define rank tipa_rank
#define pb push_back
#define mp make_pair
#define pow10 tipa_pow10
#define ll long long
#define INF 1000000000
#define EPS 1e-9
#define EPS2 1e-8
#define PI acos(-1.0)
using namespace std;
const int MOD = INF + 7;
int n , x, y;
int cntByColour[200000];
int c[200000] , w[200000];
int goodPos[200000];
ll fact[200005];
bool good[200000];
map<int , int> M;
vector<pair<int , int> > colWeight[200000];
vector<pair<pair<int , int> , int> >  weight , weights;

ll mod = 1000 * 1000 * 1000 + 7;
ll gcdExtended(ll a, ll b, ll *x, ll *y);

// Function to find modulo inverse of a
ll modInverse(ll a, ll m)
{
	ll x, y;
	ll g = gcdExtended(a, m, &x, &y);
	if (g != 1)
		cout << "Inverse doesn't exist";
	else
	{
		// m is added to handle negative x
		ll res = (x%m + m) % m;
		return res;
	}
}

// C function for extended Euclidean Algorithm
ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
	// Base Case
	if (a == 0)
	{
		*x = 0, *y = 1;
		return b;
	}

	ll x1, y1; // To store results of recursive call
	ll gcd = gcdExtended(b%a, a, &x1, &y1);

	// Update x and y using results of recursive
	// call
	*x = y1 - (b/a) * x1;
	*y = x1;

	return gcd;
}
int visited[200000];
int cnt;
vector<vector<int> > g(200000);
void dfs(int u)
{
	cnt++;
	M[c[u]]++;
	visited[u] = 1;
	for(int i = 0; i < g[u].size(); i++)
	{
		int v = g[u][i];
		if(!visited[v])
		{
			dfs(v);
		}
	}
}
int main()
{
	//freopen("input.txt" , "r" , stdin);
	fact[0] = 1;
	for(int i = 1; i <= 200000; i++)
		fact[i] = (fact[i - 1] * i) % MOD;
	scanf("%d %d %d" , &n , &x , &y);
	for(int i = 0; i < n; i++)
	{
		scanf("%d %d" , &c[i] , &w[i]);
		c[i]--;
		colWeight[c[i]].pb(mp(w[i] , i));
		weights.pb(mp(mp(w[i] , c[i]) , i));
	}
	int a1 = -1, a2 = -1;
	int c1 = -1 , c2 = -1;
	int i1 = -1 , i2 = -1;
	for(int i = 0; i < n; i++)
	{
		sort(colWeight[i].begin() , colWeight[i].end());
		if(colWeight[i].size())
			weight.pb(mp(mp(colWeight[i][0].first , i) , colWeight[i][0].second));
	}
	sort(weight.begin() , weight.end());
	sort(weights.begin() , weights.end());
	a1 = weight[0].first.first;
	c1 = weight[0].first.second;
	i1 = weight[0].second;
	if(weight.size() > 1)
	{
		a2 = weight[1].first.first;
		c2 = weight[1].first.second;
		i2 = weight[1].second;
	}
	for(int i = 0; i < weights.size(); i++)
	{
		if(c1 != weights[i].first.second && weights[i].first.first + a1 <= y)
		{
			g[i1].pb(weights[i].second);
			g[weights[i].second].pb(i1);
		}
		else
		{
			if(a2 != -1 && weights[i].first.first + a2 <= y)
			{
				g[i2].pb(weights[i].second);
				g[weights[i].second].pb(i2);
			}
		}
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = 1; j < colWeight[i].size(); j++)
		{
			int X = colWeight[i][0].second;
			int w = colWeight[i][0].first;
			if(w + colWeight[i][j].first <= x)
			{
				//cout << i << " " << w << " " << colWeight[i][j].first << endl;
				g[X].pb(colWeight[i][j].second);
				g[colWeight[i][j].second].pb(X);
			}
		}
	}
	ll ans = 1;
	int Cnt = 0;
	for(int i = 0; i < n; i++)
	{
		if(!visited[i])
		{
			dfs(i);
			//cout << 1 << " " << cnt << endl;
			Cnt += cnt;
			ans *= fact[cnt];
			ans %= MOD;
			if(cnt != 1)
			{
				for(auto it = M.begin(); it != M.end(); it++)
				{
					//cout << "IN MAP: " << it->first << " " << it->second << endl;
					ans *= modInverse(fact[it->second] , MOD);
					ans %= MOD;
				}
			}
			cnt = 0;
			M.clear();
		}
	}
	cout << ans;
}


Measured memory_bytes: 35120