#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

struct UnionFind {
  vector<int> parent;
  UnionFind (int n) : parent(n, -1) {}
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (parent[y] < parent[x]) swap(x, y);
    if (parent[x] == parent[y]) --parent[x];
    parent[y] = x;
    return true;
  }
};

const int mod = 1000000007;

struct Mod {
  int n;
  Mod () : n(0) {;}
  Mod (int m) : n(m) {
    if (n >= mod) n %= mod;
    else if (n < 0) n = (n % mod + mod) % mod;
  }
  operator int() { return n; }
};

bool operator==(Mod a, Mod b) { return a.n == b.n; }
Mod operator+=(Mod &a, Mod b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; }
Mod operator-=(Mod &a, Mod b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; }
Mod operator*=(Mod &a, Mod b) { a.n = ((long long)a.n * b.n) % mod; return a; }
Mod operator+(Mod a, Mod b) { return a += b; }
Mod operator-(Mod a, Mod b) { return a -= b; }
Mod operator*(Mod a, Mod b) { return a *= b; }
Mod operator^(Mod a, int n) {
  if (n == 0) return Mod(1);
  Mod res = (a * a) ^ (n / 2);
  if (n % 2) res = res * a;
  return res;
}

ll inv(ll a, ll p) {
  return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
Mod operator/(Mod a, Mod b) { return a * Mod(inv(b, mod)); }

#define MAX_N 1024000

Mod fact[MAX_N], factinv[MAX_N];
void init() {
  fact[0] = Mod(1); factinv[0] = 1;
  REP(i,MAX_N-1) {
    fact[i+1] = fact[i] * Mod(i+1);
    factinv[i+1] = factinv[i] / Mod(i+1);
  }
}
Mod comb(int a, int b) {
  return fact[a] * factinv[b] * factinv[a-b];
}

vector<pair<int,int>> wl[256000];
map<int,int> mapsto[256000];

void solve(ll N, ll X, ll Y, vector<ll> c, vector<ll> w) {
  init();
  REP(i,N) wl[c[i] - 1].emplace_back(int(w[i]), i);
  UnionFind uf(N);
  REP(i,N) {
    sort(ALL(wl[i]));
    for (int j = 0; j < (int)(wl[i].size()); ++j) {
      if (wl[i][0].first + wl[i][j].first <= X)
        uf.merge(wl[i][0].second, wl[i][j].second);
    }
  }
  vector<pair<int,int>> v;
  REP(i,N) {
    v.emplace_back(w[i], i);
  }
  sort(ALL(v));
  vector<pair<int,int>> vec;
  for (auto i: v) {
    if (vec.empty() || c[vec.back().second] != c[i.second])
      vec.push_back(i);
  }

  for (int i = 0; i < min(2, int(vec.size())); ++i) {
    for (int j = 0; j < N; ++j) {
      if (vec[i].first + w[j] <= Y && c[vec[i].second] != c[j]) {
        uf.merge(vec[i].second, j);
      }
    }
  }
  REP(i,N) {
    mapsto[uf.root(i)][c[i] - 1]++;
  }
  Mod res = 1;
  REP(i,N) {
    if (mapsto[i].empty()) continue;
    int sum = 0;
    for (auto j: mapsto[i]) {
      sum += j.second;
    }
    Mod prod = fact[sum];
    for (auto j: mapsto[i]) {
      prod *= factinv[j.second];
    }
    res *= prod;
  }
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll Y;
	ll X;
	scanf("%lld", &N);
	vector<ll> w(N-1+1);
	vector<ll> c(N-1+1);
	scanf("%lld", &X);
	scanf("%lld", &Y);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &c[i]);
	  scanf("%lld", &w[i]);
	}
	solve(N, X, Y, c, w);
	return 0;
}


Measured memory_bytes: 50164