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

}


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

}


// Fastest known solution for this problem: