// Slower C++ solution:
#include <algorithm>

#include <cstdio>

#include <vector>

using namespace std;



const int N = 2e5 + 10;

const int MOD = 1e9 + 7;



int n, x, y, c[N], w[N], Min1, Min2;

int f[N], cnt[N], Min[N];

vector<int> v[N];



int qpow(int a, int b) {

	int ans = 1;

	for(; b; b >>= 1, a = a * 1ll * a % MOD)

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

	return ans;

}



int get(const int &u) {

	return u == f[u] ? u : f[u] = get(f[u]);

}

void unite(int u, int v) {

	(u = get(u)) != (v = get(v)) ? f[v] = u : 0;

}



int main() {

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

	

	static int fac[N] = {1}, fav[N];

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

		fac[i] = fac[i - 1] * 1ll * i % MOD;

	fav[n] = qpow(fac[n], MOD - 2);

	for(int i = n; i >= 1; i --)

		fav[i - 1] = fav[i] * 1ll * i % MOD;

	

	w[0] = 1 << 30;

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

		scanf("%d%d", c + i, w + i);

		if(w[i] < w[Min[c[i]]]) Min[c[i]] = i;

	}



	for(int i = 1; i <= n; i ++) if(Min[i]) {

		if(w[Min[i]] < w[Min1]) Min2 = Min1, Min1 = Min[i];

		else if(w[Min[i]] < w[Min2]) Min2 = Min[i];

	}



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

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

		if(w[Min[c[i]]] + w[i] <= x) unite(Min[c[i]], i);

		if(Min2 && c[Min2] != c[i] && w[Min2] + w[i] <= y) unite(Min2, i);

		if(Min1 && c[Min1] != c[i] && w[Min1] + w[i] <= y) unite(Min1, i);

	}

	int ans = 1;

	for(int i = 1; i <= n; i ++) v[get(i)].push_back(c[i]);

	

	for(int i = 1; i <= n; i ++) if(f[i] == i) {

		int size = v[i].size();

		ans = ans * 1ll * fac[size] % MOD;

		for(int j = 0; j < size; j ++) cnt[v[i][j]] ++;

		for(int j = 0; j < size; j ++) if(cnt[v[i][j]]) {

			ans = ans * 1ll * fav[cnt[v[i][j]]] % MOD;

			cnt[v[i][j]] = 0;

		}

	}

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

	return 0;

}

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

#include<algorithm>

#define fo(i,a,b) for(i=a;i<=b;i++)

#define fd(i,a,b) for(i=a;i>=b;i--)

using namespace std;

typedef long long ll;

const int maxn=200000+10,mo=1000000007,inf=1000000005;

int mi[maxn],c[maxn],w[maxn],cnt[maxn],fac[maxn],inv[maxn];

int i,j,k,l,t,n,m,ans,num,x,y;

int qsm(int x,int y){

    if (!y) return 1;

    int t=qsm(x,y/2);

    t=(ll)t*t%mo;

    if (y%2) t=(ll)t*x%mo;

    return t;

}

int C(int n,int m){

    if (n<m||m<0) return 0;

    return (ll)fac[n]*inv[m]%mo*inv[n-m]%mo;

}

int main(){

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

    fo(i,1,n) mi[i]=inf;

    fac[0]=1;

    fo(i,1,n) fac[i]=(ll)fac[i-1]*i%mo;

    inv[n]=qsm(fac[n],mo-2);

    fd(i,n-1,0) inv[i]=(ll)inv[i+1]*(i+1)%mo;

    fo(i,1,n){

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

        mi[c[i]]=min(mi[c[i]],w[i]);

        cnt[c[i]]++;

    }

    fo(i,1,n) 

        if (mi[i]!=inf){

            if (m==0) m=i;

            else if (mi[i]<mi[m]) m=i;

        }

    t=inf;

    fo(i,1,n)

        if (mi[i]!=inf&&i!=m) t=min(t,mi[i]);

    fo(i,1,n){

        if (w[i]!=mi[c[i]]&&w[i]+mi[c[i]]<=x) continue;

        if (c[i]!=m&&w[i]+mi[m]<=y) continue;

        if (c[i]==m&&w[i]+t<=y) continue;

        cnt[c[i]]--;

    }

    num=cnt[m];

    fo(i,1,n)

        if (mi[i]!=inf&&i!=m)

            if (mi[i]+mi[m]<=y) num+=cnt[i];

    ans=1;

    fo(i,1,n)

        if (mi[i]!=inf&&(i==m||mi[i]+mi[m]<=y)){

            ans=(ll)ans*C(num,cnt[i])%mo;

            num-=cnt[i];

        }

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

}