// Slower C++ solution:
#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);

}

// Faster C++ solution for the same problem (measured speedup: 2.619477773214098x):
#include<iostream>

#include<cstdio>

typedef long long ll;

const ll mod=1000000007;

const ll inf=2147483647;

const int N=200005;

const int M=3000005;

int head[N],to[M],nxt[M];

int c[N],pos[N],cc[N],cnt;

ll w[N],fac[N],divide[N],minn[N];

bool vis[N];

ll pow(ll a,ll b){

    ll ans=1;

    while(b){

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

        b>>=1;

        a=(a*a)%mod;

    }

    return ans;

}

ll cal(ll n,ll k){

    return(((fac[n]*divide[n-k])%mod)*divide[k])%mod;

}

void dfs(int x){

    vis[x]=true;

    for(int i=head[x];i;i=nxt[i])if(!vis[to[i]])dfs(to[i]);

}

void add(int u,int v){

    to[++cnt]=v;

    nxt[cnt]=head[u];

    head[u]=cnt;

}

int n,i,a,b;

ll x,y,min1,min2,tot,ans;

int main(){

    scanf("%d %lld %lld",&n,&x,&y);

    fac[0]=1;

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

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

        fac[i]=(i*fac[i-1])%mod;

        minn[i]=inf;

    }

    divide[n]=pow(fac[n],mod-2);

    for(i=n;i>0;i--)divide[i-1]=(i*divide[i])%mod;

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

        if(w[i]<minn[c[i]]){

            minn[c[i]]=w[i];

            pos[c[i]]=i;

        }

    }

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

        if(i!=pos[c[i]]&&w[i]+minn[c[i]]<=x){

            add(i,pos[c[i]]);

            add(pos[c[i]],i);

        }

    }

    min1=min2=inf;

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

        if(w[i]<min1){

            min1=w[i];

            a=i;

        }

    }

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

        if(w[i]<=min2&&c[i]!=c[a]){

            min2=w[i];

            b=i;

        }

    }

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

        if(i==a)continue;

        if(c[i]!=c[a]&&w[i]+w[a]<=y){

            add(i,a);

            add(a,i);

        }

        if(b&&c[i]!=c[b]&&w[i]+w[b]<=y){

            add(i,b);

            add(b,i);

        }

    }

    dfs(a);

    tot=0;

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

        if(vis[i]){

            tot++;

            cc[c[i]]++;

        }

    }

    ans=1;

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

        if(cc[i]){

            ans=(ans*cal(tot,cc[i]))%mod;

            tot-=cc[i];

        }

    }

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

}