#include<cstdio>
#include<algorithm>
#include<vector>
#define N_ 201000
using namespace std;
int n, X, Y, F[N_], w[N_], C[N_], res;
int FF[N_], InvF[N_], Mod = 1000000007;
int UF[N_];
vector<int>G[N_];
int Find(int a){
    if(a==UF[a])return a;
    return UF[a] = Find(UF[a]);
}
void Make(int a, int b){
    if(a==b||b==-1)return;
    if(C[a]==C[b] && w[a]+w[b] > X)return;
    if(C[a]!=C[b] && w[a]+w[b] > Y)return;
    a = Find(a),b=Find(b);
    UF[a]=b;
}
int Pow(int a, int b){
    int r = 1;
    while(b){
        if(b&1)r=1ll*r*a%Mod;
        a=1ll*a*a%Mod;b>>=1;
    }
    return r;
}
int Get(vector<int>&P){
    sort(P.begin(),P.end());
    int i, m = P.size(), c = 0;
    int r = FF[m];
    for(i=0;i<m;i++){
        c++;
        if(i==m-1 || P[i]!=P[i+1]){
            r = 1ll*r*InvF[c]%Mod;
            c = 0;
        }
    }
    return r;
}
int main(){
    int i;
    scanf("%d%d%d",&n,&X,&Y);
    for(i=1;i<=n;i++){
        UF[i] = i;
        scanf("%d%d",&C[i],&w[i]);
        if(!F[C[i]] || w[F[C[i]]] > w[i]) F[C[i]] = i;
    }
    int M1 = 1e9, M2 = 1e9, t1 = -1, t2 = -1;
    for(i=1;i<=n;i++){
        if(!F[i])continue;
        if(M1 > w[F[i]]){
            M2 = M1, t2 = t1;
            M1 = w[F[i]], t1 = F[i];
        }
        else if(M2 > w[F[i]])M2 = w[F[i]],t2 = F[i];
    }
    for(i=1;i<=n;i++){
        Make(i, F[C[i]]);
        Make(i, t1);
        Make(i, t2);
    }
    FF[0] = 1;
    for(i=1;i<=n;i++)FF[i] = 1ll*FF[i-1]*i%Mod;
    InvF[n] = Pow(FF[n],Mod-2);
    for(i=n;i>=1;i--)InvF[i-1] = 1ll*InvF[i]*i%Mod;
    for(i=1;i<=n;i++){
        G[Find(i)].push_back(C[i]);
    }
    res = 1;
    for(i=1;i<=n;i++){
        if(!G[i].empty()) res = 1ll*res*Get(G[i])%Mod;
    }
    printf("%d\n",res);
}