// 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: 3.980189562802776x):
#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);

}