#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)
    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }
    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }
    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
/////////////////////////////////////
#define N 2000004

ll kai[N];
ll kai2[N];
ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}
ll bunbo(ll n){
    return po(n,i_5);
}
//////////////


struct Ball{
    ll c,w,num;
    ll root;
};
bool comc(Ball a,Ball b){
    if(a.c==b.c)return a.w<b.w;
    return a.c<b.c;
}
bool comw(Ball a,Ball b){
    return a.w<b.w;
}
bool comr(Ball a,Ball b){
    if(a.root==b.root)return a.c<b.c;
    return a.root<b.root;
}


int main(){fastio
    calc();
    ll n,x,y;cin>>n>>x>>y;
    Ball b[n];
    rep(i,0,n-1){
        cin>>b[i].c>>b[i].w;b[i].num=i;
    }
    sort(b,b+n,comc);
    UnionFind uf(n);
    ll pos=0;
    while(pos<=n-1){
        vector<Ball>v;v.pb(b[pos]);
        while(pos<=n-2&&b[pos].c==b[pos+1].c){
            pos++;
            v.pb(b[pos]);
        }
        rep(i,1,v.size()-1){
            if(v[0].w+v[i].w<=x){
                uf.merge(v[0].num,v[i].num);
            }else{
                break;
            }
        }
        pos++;
    }
    sort(b,b+n,comw);
    Ball f1=b[0],f2;
    f2.num=-1;
    rep(i,1,n-1){
        if(b[i].c!=b[0].c){
            f2=b[i];break;
        }
    }
    rep(i,0,n-1){
        if(f1.c==b[i].c)continue;
        if(f1.w+b[i].w<=y)uf.merge(f1.num,b[i].num);
    }
    if(f2.num!=-1){
        rep(i,0,n-1){
            if(f2.c==b[i].c)continue;
            if(f2.w+b[i].w<=y)uf.merge(f2.num,b[i].num);
        }
    }
    rep(i,0,n-1){
        b[i].root=uf.root(b[i].num);
    }
    sort(b,b+n,comr);
    //rep(i,0,n-1)cout<<b[i].root<<" ";
    
    pos=0;
    ll ans=1;
    while(pos<=n-1){
        vector<Ball>v;v.pb(b[pos]);
        while(pos<=n-2&&b[pos].root==b[pos+1].root){
            pos++;
            v.pb(b[pos]);
        }
        ll vp=0;
        ll vs=v.size();
        ans=mod(ans*kai[vs]);
        while(vp<=vs-1){
            ll cou=1;
            while(vp<=vs-2&&v[vp].c==v[vp+1].c){
                cou++;
                vp++;
            }
            vp++;
            ans=mod(ans*kai2[cou]);
        }
        pos++;
    }
    cout<<mod(ans)<<endl;
    
    return 0;
}


Measured memory_bytes: 53812