#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N], col[N], w[N]; ll fac[N], inv[N];
bool f(int x, int y){
	return w[x] < w[y];
}
map<int, int> cnt[N];
int par[N], sz[N];
int rep(int x){
	if(x == par[x]) return x;
	return par[x] = rep(par[x]);
}
void unite(int x, int y){
	x = rep(x);
	y = rep(y);
	if(x == y) return;
	if(sz[x]>sz[y]) swap(x, y);
	par[x] = y;
	sz[y] += sz[x] == sz[y];
}
int minof[N];
int tot[N];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,n,k,j,x,y;
	fac[0] = inv[0] = 1;
	Fo(i, 1, N){
		fac[i] = (i*fac[i-1])%mod;
		inv[i] = (mpow(i, mod-2)*inv[i-1])%mod;
		par[i] = i;
		sz[i] = 1;
	}
	cin >> n >> x >> y;
	Fo(i, 1, n+1){
		cin >> col[i] >> w[i];
		g[col[i]].pb(i);
	}
	Fo(i, 1, n+1){
		//uniting of color[i]
		minof[i] = mod;
		if(g[i].empty()) continue;
		sort(all(g[i]), f);
		int base = g[i][0];
		minof[i] = w[base];
		for(int v: g[i]){
			if(w[v]+w[base] <= x) unite(v, base);
		}
	}
	minof[0] = mod;
 	int mn1, mn2 = 0;
	mn1 = col[1];
	Fo(i, 1, n+1){
		if(minof[col[i]] <= minof[mn1])
			mn1 = col[i];
	}
	Fo(i, 1, n+1){
		if(col[i] != mn1) mn2 = col[i];
	}
	Fo(i, 1, n+1){
		if(col[i]!=mn1 and minof[col[i]] <= minof[mn2])
			mn2 = col[i];
	}
	int pos1, pos2 = -1;
	Fo(i, 1, n+1){
		if(col[i] == mn1 and w[i] == minof[mn1]) pos1 = i;
		if(col[i] == mn2 and w[i] == minof[mn2]) pos2 = i;
	}
	//mn1, mn2 colors ki hai minimum
	Fo(i, 1, n+1){
		if(col[i] != mn1){
			if(w[i]+minof[mn1] <= y) unite(i, pos1);
		}
		else if (pos2!=-1){
			if(w[i]+minof[mn2] <= y) unite(i, pos2);
		}
	}
	Fo(i, 1, n+1){
		tot[rep(i)]++;
		cnt[rep(i)][col[i]]++;
	}
	ll ans = 1, cur = 0;
	Fo(i, 1, n+1){
		if(i == rep(i)){
			ans *= fac[tot[i]];
			ans %= mod;
			for(auto it: cnt[i]){
				ans *= inv[it.S];
				ans %= mod;
			}
		}
	}	
	cout << ans << endl;
	
	return 0;
} 

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
	if (exp & 1) result = ((ll)result * base) % mod;
	base = ((ll)base * base) % mod;
	exp >>= 1;
	}
	return result;
}

void ipgraph(int m){
	int i, u, v;
	fo(i, m){
		cin>>u>>v; 
		u++, v++;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 47360