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

#define R register int

#define ll long long 

using namespace std;

const int N=200002;

const int mod=1e9+7;

int n,x,y,len,ans,tot,jic[N],inv[N],w[N],c[N],Mnq[N],Mnh[N];

struct Qs{int sz,vl;}Q[N];

int cmp(const Qs &x,const Qs &y){return x.vl<y.vl;}

vector<int>G[N];

int Qpow(R x,R y){

    R ans=1,bas=x;

    while(y){

        if(y&1)ans=1ll*ans*bas%mod;

        bas=1ll*bas*bas%mod,y>>=1;

    }return ans;

}

int gi(){

    R x=0,k=1;char c=getchar();

    while((c<'0'||c>'9')&&c!='-')c=getchar();

    if(c=='-')k=-1,c=getchar();

    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=getchar();

    return x*k;

}

int main(){

    n=gi(),x=gi(),y=gi(),Mnq[0]=Mnh[n+1]=2e9;

    inv[0]=inv[1]=jic[0]=jic[1]=1;

    for(R i=2;i<=n;++i)jic[i]=1ll*i*jic[i-1]%mod;

    inv[n-1]=Qpow(jic[n-1],mod-2);

    for(R i=n-2;i>=2;--i)inv[i]=1ll*inv[i+1]*(i+1)%mod;

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

        c[i]=gi(),w[i]=gi(),G[c[i]].push_back(w[i]);

    for(R i=1;i<=n;++i)sort(G[i].begin(),G[i].end());

    for(R i=1,j;i<=n;++i){

        Mnq[i]=Mnq[i-1],j=G[i].size();

        if(j)Mnq[i]=min(Mnq[i],G[i][0]);

    }

    for(R i=n,j;i>=1;--i){

        Mnh[i]=Mnh[i+1],j=G[i].size();

        if(j)Mnh[i]=min(Mnh[i],G[i][0]);

    }

    for(R i=1,lim;i<=n;++i){

        lim=G[i].size();

        if(!lim)continue;Q[++tot].vl=G[i][0],Q[tot].sz=1;

        for(R j=1;j<lim;++j)

            if(G[i][0]+G[i][j]<=x||G[i][j]+min(Mnq[i-1],Mnh[i+1])<=y)

                Q[tot].sz++;

            else break;

    }

    sort(Q+1,Q+tot+1,cmp),len=Q[1].sz,ans=inv[Q[1].sz];

    if(tot==1)return puts("1"),0;

    for(R i=2;i<=tot;++i){

        if(Q[i].vl+Q[1].vl<=y)

            len+=Q[i].sz,ans=1ll*ans*inv[Q[i].sz]%mod;

        else break;

    }

    cout<<1ll*jic[len]*ans%mod<<endl;

    return 0;

}


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

#define mod 1000000007ll

#define M 200010

using namespace std;

struct edge

{

	int to;

	int nxt;

}e[3000010];

int n,minnum,minnum2;

int color[M],dlfl[M],pos[M],vis[M];

long long val[M],minn[M];

long long fac[M],rfac[M];

long long X,Y;

long long min1 = 2147483647ll,min2 = 2147483647ll;

int head[M],cnt;

void addedge(int x,int y)

{

	e[++cnt].nxt = head[x];

	e[cnt].to = y;

	head[x] = cnt;

}

void add(int x,int y)

{

	addedge(x,y);

	addedge(y,x);

}

long long qpow(long long a,long long b)

{

	long long ans = 1,res = a;

	while(b)

	{

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

		res *= res;

		res %= mod;

		b >>= 1;

	}

	return ans;

}

long long C(long long n,long long k)

{

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

}

void init()

{

	fac[0] = 1;

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

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

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

}

void dfs(int x)

{

	vis[x] = 1;

	for(int i = head[x]; i; i = e[i].nxt)

	{

		if(!vis[e[i].to])dfs(e[i].to);

	}

}

void find()

{

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

	{

		if(val[i] < min1)

		{

			min1 = val[i];

			minnum = i;

		}

	}

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

	{

		if(val[i] <= min2 && color[i] != color[minnum])

		{

			min2 = val[i];

			minnum2 = i;

		}

	}

}

int main()

{

	scanf("%d%lld%lld",&n,&X,&Y);

	init();

	for(int i = 1;i <= n;i++)minn[i] = 2147483647ll;

	for(int i = 1;i <= n;i++)scanf("%d%lld",&color[i],&val[i]);

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

	{

		if(val[i] < minn[color[i]])

		{

			minn[color[i]] = val[i];

			pos[color[i]] = i;

		}

	}

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

	{

		if(i != pos[color[i]] && val[i] + minn[color[i]] <= X)

		{

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

		}

	}

	find();

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

	{

		if(i != minnum)

		{

			if(color[i] != color[minnum] && val[i] + val[minnum] <= Y)

			{

				add(i,minnum);

			}

			if(minnum2 && color[i] != color[minnum2] && val[i] + val[minnum2] <= Y)

			{

				add(i,minnum2);

			}

		}

		

	}

	dfs(minnum);

	long long fldl = 0;

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

	{

		if(vis[i])

		{

			dlfl[color[i]]++;

		}

	}

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

	long long ans = 1;

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

	{

		if(dlfl[i])

		{

			ans *= C(fldl,dlfl[i]);

			ans %= mod;

			fldl -= dlfl[i];

		}

	}

	printf("%lld",ans);

	return 0;

}