// Slower C++ solution:
#include<cstdio>

#include<algorithm>

#include<vector>

using namespace std;

int gi(){

	int x=0,w=1;char ch=getchar();

	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();

	if (ch=='-') w=0,ch=getchar();

	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();

	return w?x:-x;

}

const int N = 2e5+5;

const int mod = 1e9+7;

int n,X,Y,inv[N],mn[N],mn1=mod,mn2=mod,ans=1,tot;

vector<int>v[N];

int main(){

	n=gi();X=gi();Y=gi();inv[1]=1;

	for (int i=2;i<=n;++i) inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;

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

	for (int i=1,x;i<=n;++i) x=gi(),v[x].push_back(gi());

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

		if (v[i].size()){

			sort(v[i].begin(),v[i].end());

			mn2=min(mn2,mn[i]=v[i][0]);

			if (mn2<mn1) swap(mn1,mn2);

		}else mn[i]=mod;

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

		int mm=mn[i]==mn1?mn2:mn1,sz=v[i].size();

		while (sz>1&&v[i][sz-1]+mn[i]>X&&v[i][sz-1]+mm>Y) --sz,v[i].pop_back();

		if (mn[i]+mn1<=Y) ans=1ll*ans*inv[sz]%mod,tot+=sz;

	}

	for (int i=1;i<=tot;++i) ans=1ll*ans*i%mod;

	printf("%d\n",ans);return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.487969273783867x):
#include<bits/stdc++.h>

#define re register

#define For(i, j, k) for(re int i = j; i <= k; i++)

#define foR(i, j, k) for(re int i = j; i >= k; i--)

#define Cross(i, j, k) for(re int i = j; i; i = k)

#define debug(x) (cout << "#x = " << x << endl)

using namespace std;

typedef long long ll;

const ll N = 200011;

const ll p = 1e9 + 7;

const ll inf = 0x3f3f3f3f3f3f;



ll n, A, B, c[N], w[N];



namespace IO {



	#define dd (ch = getchar())

	inline ll read() {

		ll x = 0; bool f = 0; char ch = getchar();

		for (; !isdigit (ch); dd) f ^= (ch == '-');

		for (; isdigit (ch); dd)  x = (x << 1) + (x << 3) + (ch ^ 48);

		return f? -x: x;

	}

	#undef dd

	

	inline void write ( ll x ) {

		if ( x < 0 ) x = -x, putchar ('-');

		if ( x > 9 ) write ( x / 10 );

		putchar ( x % 10 | 48 );

	}

	

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	

	inline void wlnn ( ll x, ll y ) { wrn (x); wln (y); }



}



using namespace IO;



namespace Subtask1 {

	

	ll ans = 0;

	

	inline void dfs ( ll now, ll pos ) {

		if ( now == n + 1 || pos == n + 1 ) return ;

		if ( c[now] != c[pos] && w[now] + w[pos] <= B ) ans++;

		if ( ans == p ) ans = 0;

		dfs ( now, pos + 1 ); 

		if ( now != pos ) dfs ( now + 1, pos + 1 );

	}

	

	inline void main () {

		dfs ( 1, 1 );

		wln (ans + 3); exit (0);

	}

	

}



namespace Subtask2 {

	

	inline void main () {

		puts("1"); exit (0);

	}

	

}



namespace Subtask3 {

	

	ll m, mn[N], fac[N], inv[N], cnt[N];

	

	inline ll power ( ll a, ll b ) {

		ll res = 1;

		for (; b; b >>= 1, a = a * a % p) res = (b & 1)? res * a % p: res;

		return res;

	}

	

	inline ll C ( ll n, ll m ) {

		if ( n < m || m < 0 ) return 0;

		return fac[n] * inv[m] % p * inv[n - m] % p;

	}

	

	inline void Init() {

		For ( i, 1, n ) mn[i] = inf;

		fac[0] = 1;

		For ( i, 1, n ) fac[i] = fac[i - 1] * i % p;

		inv[n] = power ( fac[n], p - 2 );

		foR ( i, n - 1, 0 ) inv[i] = inv[i + 1] * (i + 1) % p;

		For ( i, 1, n )

			cnt[c[i]]++, mn[c[i]] = min ( w[i], mn[c[i]] );

	}

	

	inline void main () {

		Init();

		For ( i, 1, n ) if ( mn[i] != inf ) 

			if ( m == 0 || mn[i] < mn[m] ) m = i;

		ll t = inf;

		For ( i, 1, n ) 

			if ( mn[i] != inf && i != m ) t = min ( t, mn[i] );

		For ( i, 1, n ) 

			if ( (w[i] == mn[c[i]] || 

				w[i] + mn[c[i]] > A) 

					&& (c[i] == m || w[i] + mn[m] > B) 

						&& (c[i] != m || w[i] + t > B) ) cnt[c[i]]--;

		ll num = cnt[m];

		For ( i, 1, n )

			if ( mn[i] != inf && i != m )

				if ( mn[i] + mn[m] <= B ) num += cnt[i];

		ll ans = 1;

		For ( i, 1, n ) if ( mn[i] != inf 

			&& (i == m || mn[i] + mn[m] <= B) )

				ans = ans * C(num, cnt[i]) % p, num -= cnt[i];

		wln (ans); exit (0);

	}

	

}



ll f = 1;



int main() {

//	freopen("keep.in", "r", stdin);

//	freopen("keep.out", "w", stdout);

	n = read(), A = read(), B = read();

	For ( i, 1, n ) {

		c[i] = read(), w[i] = read();

		if ( c[i] != c[1] ) f = 0;

	}

//	if ( n <= 20 ) 

//				Subtask1::main ();

	if (f) 	Subtask2::main ();

	else 	Subtask3::main (); return 0;

}



/*

4 7 3

3 2

4 3

2 1

4 4



2



1 1 1

1 1



1

*/