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

using namespace std;

#define int long long

const int mod=(1e9+7);

int n;

int fac[200001],inv[200001];

int qpow(int a,int b){

	int ans=1;

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

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

	return ans;

}

int C(int n,int m){

	if(!n)return 1;

	if(m<n)return 0;

	return fac[m]*inv[m-n]%mod*inv[n]%mod;

}

void init(){

	fac[0]=1;

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

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

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

}

int col[200001];

int w[200001];

int allmin=0x7fffffff,secmin=0x7fffffff;

int minpos,secpos;

int minn[200001];

int A,B;

int sum[200001],allsum;

signed main(){

	memset(minn,0x7f,sizeof(minn));

	scanf("%lld%lld%lld",&n,&A,&B);

	init();

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

		scanf("%lld%lld",&col[i],&w[i]);

		minn[col[i]]=min(minn[col[i]],w[i]);

		if(w[i]<allmin){

			secpos=minpos;

			minpos=i;

			secmin=allmin;

			allmin=w[i];

		}

		else if(w[i]<secmin){

			secpos=i;

			secmin=w[i];

		}

	}

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

		if(minn[col[i]]+w[i]<=A){

			w[i]=minn[col[i]];

		}

		if(col[i]!=col[minpos]&&w[i]+w[minpos]<=B){

			allsum++;

			sum[col[i]]++;

		}

		if(col[i]==col[minpos]&&w[i]+w[secpos]<=B){

			allsum++;

			sum[col[i]]++;

		}

	}

	int ans=1;

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

		if(sum[i]){

			ans=(ans*C(sum[i],allsum))%mod;

			allsum-=sum[i];

		}

	}

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

}

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



#define MAXN 200005

#define INF 0x3f3f3f3f



typedef long long lint;



using namespace std;



const int mod = 1e9 + 7;

int n, x, y;

int c[MAXN], w[MAXN], mini[MAXN];

int sum[MAXN], amount;

int first, second, firstc;

lint fac[MAXN], inf[MAXN];



int read() {

    char c = getchar();

    int x = 0;

    while (!isdigit(c))

        c = getchar();

    while (isdigit(c)) {

        x = (x << 3) + (x << 1) + c - '0';

        c = getchar();

    }

    return x;

}



lint power(lint a, int b) {

    lint res = 1;

    while (b) {

        if (b & 1)

            res = res * a % mod;

        a = a * a % mod;

        b >>= 1;

    }

    return res;

}



void init() {

    fac[0] = inf[0] = 1;

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

        fac[i] = fac[i - 1] * i % mod;

    inf[n] = power(fac[n], mod - 2);

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

        inf[i] = inf[i + 1] * (i + 1) % mod;

}



int main() {

//    freopen("15.txt", "r",stdin);

    n = read();

    x = read();

    y = read();

    init();

    memset(mini, 0x3f, sizeof(mini));

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

        c[i] = read();

        w[i] = read();

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

    }

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

        if (mini[c[i]] + w[i] <= x)

            w[i] = mini[c[i]];

    first = second = INF;

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

        if (mini[i] < first) {

            second = first;

            first = mini[i];

            firstc = i;

        }

        else if (mini[i] < second)

            second = mini[i];

//    printf("%d %d\n", first, second);

    if (first + second <= y)

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

            if (c[i] == firstc && w[i] != first && w[i] + second <= y)

                w[i] = first;

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

        if (c[i] == firstc && w[i] == first) {

//            cout << "first: " << i << endl;

            ++sum[c[i]];

            ++amount;

        }

        else if (c[i] != firstc && w[i] + first <= y) {

//            cout << "second: " << i << endl;

            ++sum[c[i]];

            ++amount;

        }

    lint res = fac[amount];

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

        res = res * inf[sum[i]] % mod;

    printf("%lld\n", res);

}