#include <bits/stdc++.h>
using namespace std;

#define endl '\n'

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(15);
}
#define LL long long
//Fast Reader
// template<class T>inline bool read(T &x){int c=getchar_unlocked();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar_unlocked();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar_unlocked())x=x*10+c-'0'; x*=sgn; return ~c;}
double tick(){static clock_t oldt;clock_t newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt = newt;return diff;} 
 
LL mulmod(LL a,LL b, LL m){LL q=(LL)(((long double)a*(long double)b)/(long double)m);LL r=a*b-q*m;if(r>m)r%=m;if(r<0)r+=m;return r;}/* for TOO LARGE mod of the order 10^18 etc */
 
template<typename T>T mod(T a,T b){while(a < 0)a+=b ;return a%b ;}
template <typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mod(x*p, m);p=mod(p*p, m);n>>=1;}return x;}
template <typename T>T power(T e,T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template <typename T> T InverseEuler(T a, T m){return (a==1? 1 : power(a, m-2, m));}/*use IFF m is a prime number */
template<typename T>inline T gcd(T a, T b){T c;while (b){ c = b;b = a % b;a = c;}return a;}
template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));}

const long long MOD = 1e9 + 7 ;
const int MAXN = 2e5 + 5 ; 
long long fact[MAXN] ;
long long finv[MAXN] ;
vector<int> g[MAXN] ;
int vis[MAXN] ;
vector<pair<int,int>> vals[MAXN] ;
vector< pair<int,pair<int,int>> > minvals ;
int compsz = 0 ;
long long deno ;
int seen[MAXN] ;
int col[MAXN] ;
int colcnt[MAXN] ;
int seenid[MAXN] ;
void dfs(int u){
    vis[u] = 1 ;
    compsz += 1 ;
    if(!seen[col[u]]){
        int k = colcnt[col[u]] ;
        deno = deno*finv[k] ;
        deno %= MOD ;
        seen[col[u]] = 1 ;
    }
    for(auto v:g[u]) {
        if(!vis[v]){
            dfs(v); 
        }
    }
}
int main(int argc,char* argv[]) { 
    io() ;
    #ifndef ONLINE_JUDGE
     //   freopen("inp.txt", "r", stdin) ;
        // freopen("out.txt", "w", stdout);
    #endif
    fact[0] = 1; 
    for(int i = 1 ; i < MAXN ; i++){
        fact[i] = (fact[i-1]*i)%MOD ;
    }
    finv[MAXN - 1] = InverseEuler(fact[MAXN - 1] , MOD)%MOD ;
    for(int i = MAXN - 2 ; i >= 0 ; i--){
        finv[i] = (finv[i+1]*1ll*(i+1) )%MOD;
    }
    int n ;
    cin >> n ;
    int X,Y ;
    cin >> X >> Y ;
    for(int i = 1 ; i <= n ; i++){
        int c,wt ;
        cin >> c >> wt ;
        col[i] = c ;
        vals[c].push_back({wt, i}) ;
    }
    if(n == 1){
        cout << 1 << endl ;
        return 0 ;
    }
    for(int i = 1 ; i <= n ; i++){
        sort(vals[i].begin(), vals[i].end()); 
    }

    for(int i = 1 ; i <= n ; i++){
        if(vals[i].size() == 0) continue ;
        int x = vals[i][0].second ;
        int wx = vals[i][0].first ;
        minvals.push_back({wx , {x,i}}) ;
        if(!seenid[x]){
            seenid[x] = 1 ;
            colcnt[i]++ ;
        }
        for(int j = 1 ; j < vals[i].size() ; j++){
            int y = vals[i][j].second ;
            int wy = vals[i][j].first ;
            if((wx + wy) <= X){
                g[x].push_back(y) ;
                g[y].push_back(x) ;
                if(!seenid[y]){
                    seenid[y] = 1 ;
                    colcnt[i]++ ;
                }
            }
        }
    }
    sort(minvals.begin() , minvals.end()) ;
    for(int i = 0 ; i < minvals.size() ; i++){
        if(i == 2){
            break ;
        }
        int wt = minvals[i].first ;
        int c = minvals[i].second.second ;
        int id = minvals[i].second.first ;
        if(!seenid[id]){
            seenid[id] = 1 ;
            colcnt[col[id]]++ ;
        }
        for(int j = 1 ; j <= n ; j++){
            if(j != c){
                for(auto it:vals[j]){
                    int ww = it.first ;
                    if( (wt + ww) <= Y){
                        g[id].push_back(it.second) ;
                        g[it.second].push_back(id);
                        if(!seenid[it.second]){
                            seenid[it.second] = 1 ;
                            colcnt[col[it.second]]++ ;
                        } 
                    }
                }   
            }   
        }
    }
    long long ans = 1 ;
    for(int i = 1 ; i <= n ; i++){
        if(!vis[i]){
            compsz = 0 ;
            deno = 1 ;
            dfs(i) ;
            ans = (((ans*deno)%MOD)*fact[compsz])%MOD ;
        }
    }
    cout << ans << endl; 
    return 0 ; 
}

Measured memory_bytes: 31232