#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head


struct Mod{
  unsigned n;
  Mod() : n(0){}
  Mod( ll x ){
    if( x < 0 ) n = x%MOD+MOD;
    else n = x%MOD;
  }
};
Mod operator + ( Mod a  , Mod b ){ return Mod( a.n + b.n ); }
Mod operator +=( Mod &a , Mod b ){ return a = a + b; }
Mod operator - ( Mod a ){ return Mod( MOD - a.n ); }
Mod operator - ( Mod a  , Mod b ){ return Mod( a.n + MOD - b.n ); }
Mod operator -=( Mod &a , Mod b ){ return a = a - b; }
Mod operator * ( Mod a  , Mod b ){ return Mod( (ll)a.n * b.n ); }
Mod operator *=( Mod &a , Mod b ){ return a = a * b; }
Mod modpow( Mod x , ll k ){
  Mod res = 1;
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}
ll extgcd( ll a , ll b , ll &x , ll &y ){
  ll d = a;
  if( b != 0 ){
    d = extgcd( b , a % b , y , x );
    y -= a / b * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}
Mod inv( Mod a ){ ll x, y; assert( extgcd( a.n , MOD , x , y ) == 1 ); return Mod( x ); }
Mod operator / ( Mod a  , Mod b ){ return Mod( (ll)a.n * inv(b).n ); }
Mod operator /=( Mod &a , Mod b ){ return a = a / b; }


struct Factorial{
  vector<Mod> v;
  Factorial( int max_n ){
    v = vector<Mod>( max_n , 1 );
    FOR( i , 1 , max_n ) v[i] = v[i-1] * i;
  }
  int size(){
    return v.size();
  }
  Mod operator [] ( int id ){
    return v.at(id);
  }
};

struct Factorial_inv{
  vector<Mod> v;
  Factorial_inv( Factorial &f ){
    v = vector<Mod>( f.size() );
    REP( i , f.size() ) v[i] = inv( f[i] );
  }
  Mod operator [] ( int id ){
    return v.at(id);
  }
};

struct Combination{
  Factorial *f;
  Factorial_inv *finv;
  Combination( Factorial &arg_f , Factorial_inv &arg_finv ){
    f = &arg_f;
    finv = &arg_finv;
  }
  Mod operator () ( int a , int b ){
    return (*f)[a] * (*finv)[b] * (*finv)[a-b];
  }
};

Factorial fact( 200010 );
Factorial_inv finv( fact );
Combination comb( fact , finv );
   
struct Unionfind{
  vi size, par;
  Unionfind(){}
  Unionfind( int n ) :  size(n,1), par(n){
    REP( i , n ) par[i] = i;
  }
  void init( int n ){
    size = vi( n , 1 );
    par.resize( n );
    REP( i , n ) par[i] = i;
  }
  int find( int x ){
    if( par[x] == x ) return x;
    return par[x] = find( par[x] );
  }
  bool unite( int x , int y ){
    x = find(x);
    y = find(y);
    if( x == y ) return false;
    if( size[y] < size[x] ) swap( x , y );
    par[x] = y;
    size[y] += size[x];
    return true;
  }
  bool same( int x , int y ){
    return find(x) == find(y);
  }
};


Unionfind uf;

int n, x, y;
vi v[200010];
int sum[200010];

int col[200010];
vi res[200010];

void internal( int t ){
  if( not v[t].empty() ){
    int mx = x - v[t][0];
    int it = upper_bound( ALL(v[t]), mx ) - v[t].begin();
    REP( i , it-1 ){
      uf.unite( sum[t]+i, sum[t]+i+1 );
    }
  }
}

void external( int a, int t ){
  int mx = y - a;
  vi ad;
  ad.pb( t );
  REP( i , n ){
    if( i == t ){
      continue;
    }
    int it = upper_bound( ALL(v[i]), mx ) - v[i].begin();
    REP( j , it-1 ){
      uf.unite( sum[i]+j, sum[i]+j+1 );
    }
    if( it > 0 ){
      ad.pb( i );
    }
  }
  REP( i , SZ(ad)-1 ){
    uf.unite( sum[ad[i]], sum[ad[i+1]] );
  }
}

int main(){
  
  n = in();
  x = in();
  y = in();
  REP( i , n ){
    int c = in() - 1;
    int w = in();
    v[c].pb( w );
  }

  REP( i , n ){
    SORT( v[i] );
    sum[i+1] = sum[i] + SZ(v[i]);
  }

  int it = 0;
  REP( i , n ){
    REP( j , SZ(v[i]) ){
      col[it++] = i;
    }
  }

  /*
  SHOWA( col, n );
  
  REP( i , n ){
    if( not v[i].empty() ){
      SHOWA( v[i], SZ(v[i]) );
    }
  }
  */

  uf.init( n );

  REP( i , n ){
    internal( i );
  }

  vpi mw(0);
  REP( i , n ){
    if( not v[i].empty() ){
      mw.pb( v[i][0] , i );
    }
  }
  SORT( mw );

  external( mw[0].fi, mw[0].se );
  if( SZ(mw) >= 2 ){
    external( mw[1].fi, mw[1].se );
  }

  REP( i , n ){
    res[ uf.find(i) ].pb( col[i] );
  }

  Mod ans = 1;
  REP( i , n ){
    if( not res[i].empty() ){
      SORT( res[i] );
      ans *= fact[ SZ(res[i]) ];
      int cnt = 0;
      int prv = res[i][0];
      // cout << "* " << SZ(res[i]) << " ";
      YYS( w , res[i] ){
        if( w != prv ){
          // cout << cnt << " ";
          ans *= finv[cnt];
          cnt = 1;
        } else {
          cnt++;
        }
        prv = w;
      }
      ans *= finv[cnt];
      // cout << cnt << " ";
      // cout << endl;
    }
  }

  printf( "%d\n", (int)ans.n );
  
  return 0;
}


Measured memory_bytes: 25200