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

}


// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem: