#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

constexpr int MOD = 1000000007;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};


vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(n); return n < 0 ? 0 : I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

struct unionfind {
  vector<int> dat;

  unionfind(int n) : dat(n, -1) {}

  int find(int x) {
    if (dat[x] < 0) return x;
    return dat[x] = find(dat[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (dat[x] > dat[y]) swap(x, y);
    dat[x] += dat[y];
    dat[y] = x;
  }

  int size(int x) {
    return -dat[find(x)];
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N, X, Y; cin >> N >> X >> Y;
  vector<int> C(N), W(N); rep(i, N) cin >> C[i] >> W[i];
  vector<int> ord(N); rep(i, N) ord[i] = i;
  sort(range(ord), [&](int i, int j) { return W[i] < W[j]; });
  map<int, int> mp;
  for (int i : ord) {
    if (not mp.count(C[i])) mp[C[i]] = i;
  }
  if (mp.size() == 1) {
    cout << 1 << endl;
    return 0;
  }
  unionfind uf(N);
  int l = ord[0];
  int k = -1;
  for (int i : ord) {
    if (C[i] != C[l]) {
      k = i;
      break;
    }
  }
  rep(i, N) {
    if (C[i] != C[k] && W[i] + W[k] <= Y) uf.unite(i, k);
    if (C[i] != C[l] && W[i] + W[l] <= Y) uf.unite(i, k);
    if (W[i] + W[mp[C[i]]] <= X) uf.unite(i, mp[C[i]]);
  }
  vector<map<int, int>> f(N);
  rep(i, N) {
    f[uf.find(i)][C[i]]++;
  }
  mint ans = 1;
  rep(i, N) {
    int cnt = 0;
    mint prod = 1;
    for (auto kv : f[i]) {
      prod *= R(kv.second);
      cnt += kv.second;
    }
    prod *= F(cnt);
    ans *= prod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 29420