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

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<vector>

#define MAX 200200

#define MOD 1000000007

using namespace std;

#define ll long long

inline int read()

{

	int x=0;bool t=false;char ch=getchar();

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

	if(ch=='-')t=true,ch=getchar();

	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();

	return t?-x:x;

}

int n,X,Y,ans;

struct Ball{int c,w;}B[MAX];

bool operator<(Ball a,Ball b){if(a.c!=b.c)return a.c<b.c;return a.w<b.w;}

int jc[MAX],jv[MAX],inv[MAX];

int pmn[MAX],smn[MAX],sz[MAX],W[MAX],p[MAX];

bool cmp(int i,int j){return W[i]<W[j];}

int main()

{

	n=read();X=read();Y=read();

	for(int i=1;i<=n;++i)B[i].c=read(),B[i].w=read();

	jc[0]=jv[0]=inv[0]=inv[1]=1;

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

	for(int i=1;i<=n;++i)jc[i]=1ll*jc[i-1]*i%MOD,jv[i]=1ll*jv[i-1]*inv[i]%MOD;

	sort(&B[1],&B[n+1]);

	memset(pmn,63,sizeof(pmn));

	memset(smn,63,sizeof(smn));

	memset(W,63,sizeof(W));

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

	{

		j=i;while(j<n&&B[i].c==B[j+1].c)++j;

		pmn[B[i].c]=smn[B[i].c]=B[i].w;

	}

	for(int i=1;i<=n;++i)pmn[i]=min(pmn[i],pmn[i-1]);

	for(int i=n;i>=1;--i)smn[i]=min(smn[i],smn[i+1]);

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

	{

		j=i;while(j<n&&B[i].c==B[j+1].c)++j;

		int d=min(pmn[B[i].c-1],smn[B[i].c+1]);

		int cnt=1;

		for(int k=i+1;k<=j;++k)

			if(B[i].w+B[k].w<=X||B[k].w+d<=Y)++cnt;

			else break;

		sz[B[i].c]=cnt;W[B[i].c]=B[i].w;

	}

	for(int i=1;i<=n;++i)p[i]=i;

	sort(&p[1],&p[n+1],cmp);

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

		if(i==1||W[p[i]]+W[p[1]]<=Y)

			ans+=sz[p[i]];

	ans=jc[ans];

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

		if(i==1||W[p[i]]+W[p[1]]<=Y)

			ans=1ll*ans*jv[sz[p[i]]]%MOD;

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

	return 0;

}


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

using namespace std;

#define int long long

const int mod=(1e9+7);

int n;

int fac[200001],inv[200001];

int qpow(int a,int b){

	int ans=1;

	for(;b;b>>=1,a=a*a%mod)

	if(b&1)ans=ans*a%mod;

	return ans;

}

int C(int n,int m){

	if(!n)return 1;

	if(m<n)return 0;

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

}

void init(){

	fac[0]=1;

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

	inv[n]=qpow(fac[n],mod-2);

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

}

int col[200001];

int w[200001];

int allmin=0x7fffffff,secmin=0x7fffffff;

int minpos,secpos;

int minn[200001];

int A,B;

int sum[200001],allsum;

signed main(){

	memset(minn,0x7f,sizeof(minn));

	scanf("%lld%lld%lld",&n,&A,&B);

	init();

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

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

		minn[col[i]]=min(minn[col[i]],w[i]);

		if(w[i]<allmin){

			secpos=minpos;

			minpos=i;

			secmin=allmin;

			allmin=w[i];

		}

		else if(w[i]<secmin){

			secpos=i;

			secmin=w[i];

		}

	}

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

		if(minn[col[i]]+w[i]<=A){

			w[i]=minn[col[i]];

		}

		if(col[i]!=col[minpos]&&w[i]+w[minpos]<=B){

			allsum++;

			sum[col[i]]++;

		}

		if(col[i]==col[minpos]&&w[i]+w[secpos]<=B){

			allsum++;

			sum[col[i]]++;

		}

	}

	int ans=1;

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

		if(sum[i]){

			ans=(ans*C(sum[i],allsum))%mod;

			allsum-=sum[i];

		}

	}

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

}