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

#define reg register



using namespace std;



typedef long long ll;

const int maxn = 200005;

const int mod = 1e9 + 7;

const int INF = 0x7f7f7f7f;



inline int read() {

    reg int s = 0, t = 0; reg char ch = getchar();

    while (!isdigit(ch)) t |= ch == '-', ch = getchar();

    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();

    return t ? -s : s;

}



int n, x, y, ans = 1, sum;

int Size[maxn], fact[maxn], inv[maxn];

int c[maxn], w[maxn];

struct Edge { int to, nxt; } p[maxn << 3];

int minpos[maxn], minval[maxn];

bool used[maxn];



int cnt, head[maxn];

inline void addedge(reg int u, reg int v) {

    p[++cnt].to = v, p[cnt].nxt = head[u], head[u] = cnt;

    p[++cnt].to = u, p[cnt].nxt = head[v], head[v] = cnt;

}



inline void dfs(reg int u) {

    used[u] = true;

    for (reg int i = head[u]; i; i = p[i].nxt)

        if (!used[p[i].to]) dfs(p[i].to);

}



inline void build_same() {

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

        if (i != minpos[c[i]] && w[i] + minval[c[i]] <= x) addedge(i, minpos[c[i]]);

}



inline void build_diff() {

    int First, Second, FirstVal = INF, SecondVal = INF;

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

        if (w[i] < FirstVal) FirstVal = w[i], First = i;

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

        if (w[i] < SecondVal && c[i] != c[First]) SecondVal = w[i], Second = i;

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

        if (i == First) continue;

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

        if (SecondVal != INF && c[i] != c[Second] && w[i] + w[Second] <= y) addedge(i, Second);

    }

    dfs(First);

}



inline int mod_pow(reg int a, reg int b) {

    reg int ans = 1;

    while (b) {

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

        b >>= 1, a = 1LL * a * a % mod;

    }

    return ans;

}



inline int calc(reg int x, reg int y) {

    return 1LL * fact[x] * inv[y] % mod * inv[x - y] % mod;

}



inline void init() {

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

    fact[0] = 1; for (reg int i = 1; i < maxn; i++) fact[i] = 1LL * fact[i - 1] * i % mod;

    inv[maxn - 1] = mod_pow(fact[maxn - 1], mod - 2);

    for (reg int i = maxn - 2; i >= 0; i--) inv[i] = 1LL * inv[i + 1] * (1LL * i + 1LL) % mod;

}



int main() {

    ios::sync_with_stdio(false);

    n = read(), x = read(), y = read(), init();

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

        c[i] = read(), w[i] = read();

        if (minval[c[i]] > w[i]) minval[c[i]] = w[i], minpos[c[i]] = i;

    }

    build_same(), build_diff();

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

        if (used[i]) Size[c[i]]++;

    for (reg int i = 1; i <= n; i++) sum += Size[i];

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

        if (Size[i]) ans = 1LL * ans * calc(sum, Size[i]) % mod, sum -= Size[i];

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.5194591851486052x):
#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);

}