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

using namespace std;

#define rep(i,a,b) for(register int i=(a);i<=(b);++i)

#define dep(i,b,a) for(register int i=(b);i>=(a);--i)

inline char gc(){

	static char buf[100000],*p1=buf,*p2=buf;

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

}

inline int rd(){

	int x=0,fl=1;char ch=gc();

	for(;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;

	for(;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);

	return x*fl;

}

const int N=200002,M=1e9+7;

int n,X,Y,sum,ans,jl[N],mn[N],val[N],fac[N],ny[N],col[N];

int pw(int x,int y){

	int z=1;

	for (;y;y>>=1,x=1ll*x*x%M)

		if (y&1) z=1ll*z*x%M;

	return z;

}

int C(int aa,int bb){return 1ll*fac[bb]*ny[aa]%M*ny[bb-aa]%M;}

int main(){

	n=rd(),X=rd(),Y=rd();

	fac[0]=1;

	rep(i,1,n){

		col[i]=rd(),val[i]=rd();

		jl[col[i]]++;

		mn[i]=1e9;

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

	}

	ny[n]=pw(fac[n],M-2);

	dep(i,n,1) ny[i-1]=(1ll*ny[i]*i)%M;

	rep(i,1,n) mn[col[i]]=min(mn[col[i]],val[i]);

	int mx=0,mxx=0;

	rep(i,1,n)

		if (mn[i]!=1e9)

			if (!mx || mn[i]<mn[mx]) mxx=mx,mx=i;

			else if(!mxx || mn[i]<mn[mxx]) mxx=i;

	rep(i,1,n)

		if (!(mn[col[i]]!=val[i] && mn[col[i]]+val[i]<=X || col[i]==mx && val[i]+mn[mxx]<=Y || col[i]!=mx && val[i]+mn[mx]<=Y)) jl[col[i]]--;

	ans=1,sum=jl[mx];

	rep(i,1,n)

		if (i!=mx && mn[i]+mn[mx]<=Y) sum+=jl[i],ans=1ll*ans*C(jl[i],sum)%M;

	printf("%d",ans);

} 

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

#define ll long long

#define mod 1000000007ll

struct Edge{

    int to,nex;

}edge[3000010];

int c[200010],head[200010],pos[200010],cnt[200010],tot;

ll w[200010],fac[200010],rfac[200010],min[200010];

bool v[200010];

ll pow(ll a,ll b){

    ll ans=1,base=a;

    while(b){

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

        base=(base*base)%mod;

        b>>=1;

    }

    return ans;

}

ll C(ll n,ll k){

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

}

void add(int a,int b){

    tot++;

    edge[tot].to=b;

    edge[tot].nex=head[a];

    head[a]=tot;

}

void dfs(int x){

    v[x]=1;

    for(int i=head[x];i;i=edge[i].nex){

        if(!v[edge[i].to])dfs(edge[i].to);

    }

}

int main(){

    int n,i,fir,sec=0;

    ll X,Y,min1,min2,tot,ans;

    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;

        min[i]=2147483647;

    }

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

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

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

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

            min[c[i]]=w[i];

            pos[c[i]]=i;

        }

    }

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

        if(i!=pos[c[i]]&&w[i]+min[c[i]]<=X){

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

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

        }

    }

    min1=min2=2147483647;

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

        if(w[i]<min1){

            min1=w[i];

            fir=i;

        }

    }

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

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

            min2=w[i];

            sec=i;

        }

    }

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

        if(i==fir)continue;

        if(c[i]!=c[fir]&&w[i]+w[fir]<=Y){

            add(i,fir);

            add(fir,i);

        }

        if(sec&&c[i]!=c[sec]&&w[i]+w[sec]<=Y){

            add(i,sec);

            add(sec,i);

        }

    }

    dfs(fir);

    tot=0;

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

        if(v[i]){

            tot++;

            cnt[c[i]]++;

        }

    }

    ans=1;

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

        if(cnt[i]){

            ans=(ans*C(tot,cnt[i]))%mod;

            tot-=cnt[i];

        }

    }

    printf("%lld",ans);

}