// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int mod=1e9+7;

const int N=2e5+5;

int n,A,B,cnt,ans1,ans2,num,c[N],w[N],jc[N],inv[N],fa[N],a[N],id[N],sum[N],xu[N];

vector<int>b[N];

struct node{

	int val,id;

}xjh[N];

char buf[1<<21],*p1=buf,*p2=buf;

inline int gc()

{

	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;

}

inline int read()

{

	int res=0,f=0;

	char c;

	c=gc();

	while(!isdigit(c))

	{

		if(c=='-')f=1;

		c=gc();

	}

	while(isdigit(c))

	{

		res=res*10+c-48;

		c=gc();

	}

	if(f)return -res;

	else return res;

}

int find(int x)

{

	if(fa[x]==x)return x;

	fa[x]=find(fa[x]);

	return fa[x];

}

int kuai(int a,int b)

{

	if(b==1)return a;

	int x=kuai(a,b/2);

	if(b%2==0)return x*x%mod;

	else return x*x%mod*a%mod;

}

bool cmp(node a,node b)

{

	return a.val<b.val;

}

signed main()

{

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

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

	{

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

		xu[i]=c[i];

	}

	sort(xu+1,xu+n+1);

	int len=unique(xu+1,xu+n+1)-xu-1;

	for(int i=1;i<=len;i++)xjh[i].val=1e18;

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

	{

		c[i]=lower_bound(xu+1,xu+len+1,c[i])-xu;

		if(xjh[c[i]].val>w[i])

		{

			xjh[c[i]].val=w[i];

			xjh[c[i]].id=i;

		}

	}

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

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

		if(w[i]+xjh[c[i]].val<=A)fa[find(i)]=xjh[c[i]].id;

	sort(xjh+1,xjh+len+1,cmp);

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

		if(c[i]!=c[xjh[1].id]&&w[i]+xjh[1].val<=B)fa[find(i)]=xjh[1].id;

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

		if(c[i]==c[xjh[1].id]&&w[i]+xjh[1].val<=A)fa[find(i)]=xjh[1].id;

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

		if(c[i]==c[xjh[1].id]&&w[i]+xjh[2].val<=B)fa[find(i)]=xjh[1].id;

	jc[0]=1ll;

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

	inv[1]=1ll;

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

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

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

	{

		if(!a[find(i)])

		{

			id[find(i)]=++cnt;

			a[find(i)]=1;

		}

		sum[id[find(i)]]++;

		b[id[find(i)]].push_back(c[i]);

	}

	for(int i=1;i<=cnt;i++)sort(b[i].begin(),b[i].end());

	ans1=1ll;

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

	{

		ans2=jc[sum[i]];

		num=1ll;

		for(int j=1;j<sum[i];j++)

			if(b[i][j]!=b[i][j-1])

			{

				ans2=ans2*inv[num]%mod;

				num=1ll;

			}

			else num++;

		

		ans2=ans2*inv[num]%mod;

		ans1=ans1*ans2%mod;

	}

	cout<<ans1;

	return 0;

}

/*

3 7 5

1 3

1 4

2 2

*/

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

#define swap mswap

#define max(a,b) (a>b?a:b)

#define min(a,b) (a<b?a:b)

#define int long long 

using namespace std;

const int big=0x7fffffffffffff;

void swap(int &x,int &y)

{

    x^=y^=x^=y;

}

void read(int &x)

{

    x=0;

    char ch=getchar();

    int pd=1;

    while(ch<'0'||ch>'9')

    {

        if(ch=='-')

        {

            pd=-pd;

        }

        ch=getchar();

    }

    while(ch<='9'&&ch>='0')

    {

        x=x*10+ch-'0';

        ch=getchar();

    }

    x*=pd;

}

void write(const int &x)

{

    char f[100001];

    int s=0;

    int tmp=x;

    if(tmp==0)

    {

        putchar('0');

        return;

    }

    if(tmp<0)

    {

        tmp=-tmp;

        putchar('-');

    }

    while(tmp>0)

    {

        f[s++]=tmp%10+'0';

        tmp/=10;

    }

    while(s>0)

    {

        putchar(f[--s]);

    }

}



const int mod=1e9+7;

const int N=2e5+10;

int jie[N],ni[N],n,A,B;

int c[N],w[N],minn[N],cnt[N];

int sum,ans=1;

int ksm(int x,int y)

{

	int ans=1;

	while(y)

	{

		if(y&1)

		{

			ans=(ans*x)%mod;

		}

		x=(x*x)%mod;

		y>>=1;

	}

	return ans%mod;

}

int zuhe(int x,int y)

{

	return ((jie[x]*ni[y])%mod*ni[x-y])%mod;

}

signed main()

{

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

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

	jie[0]=1;

	read(n);

	read(A);

	read(B);

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

	{

		read(c[i]);

		read(w[i]);

		minn[i]=big;

		cnt[c[i]]++;

		jie[i]=jie[i-1]*i%mod;

	}

	

	ni[n]=ksm(jie[n],mod-2);

	for(register int i=n-1;i>=0;--i)

	{

		ni[i]=(ni[i+1]*(i+1))%mod;

//		cout<<ni[i]<<endl;

	}

	

//	cout<<zuhe(3,1)<<"   QWQ"<<endl;

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

	{

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

	}

	int min1=0,allmin=0;

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

	{

		if(minn[i]!=big)

		{

			if(!min1||minn[i]<minn[min1])

			{

				allmin=min1;

				min1=i;

			}

			else 

			{

				if(!allmin||minn[i]<minn[allmin])

				{

					allmin=i;

				}

			}

		}

	}

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

	{

		if(minn[c[i]]!=w[i]&&w[i]+minn[c[i]]<=A)continue;

		if(c[i]==min1&&w[i]+minn[allmin]<=B)continue;

		if(c[i]!=min1&&w[i]+minn[min1]<=B)continue;

		cnt[c[i]]--;

	}

	sum=cnt[min1];

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

	{

		if(i!=min1&&minn[i]+minn[min1]<=B)

		{

			sum+=cnt[i];

//			cout<<sum<<endl;

			ans=(ans*zuhe(sum,cnt[i]))%mod;

//			cout<<ans<<endl;

		}

	}

	write(ans);

}