#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

int mul(int a, int b) {
  return (long long) a * b % mod;
}

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

const int maxn = (int) 2e5 + 5;
int f[maxn], inv[maxn], finv[maxn];

void precalc() {
  f[0] = 1;
  for (int i = 1; i < maxn; i++) {
    f[i] = mul(f[i - 1], i);
  }
  inv[1] = 1;
  for (int i = 2; i < maxn; i++) {
    inv[i] = (mod - (long long) (mod / i) * inv[mod % i] % mod) % mod;
  }
  finv[0] = 1;
  for (int i = 1; i < maxn; i++) {
    finv[i] = mul(finv[i - 1], inv[i]);
  }
}

int n, x, y;
int c[maxn], w[maxn];
vector< pair<int, int> > a[maxn];

int read() {
  if (scanf("%d%d%d", &n, &x, &y) < 3) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    a[i].clear();
  }
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &c[i], &w[i]);
    c[i]--;
    a[c[i]].push_back(make_pair(w[i], i));
  }
  return true;
}

int p[maxn], ts[maxn];
vector<int> comp[maxn];
pair<int, int> cs[maxn];

int get(int x) {
  return x == p[x] ? x : p[x] = get(p[x]);
}

void unite(int x, int y) {
  x = get(x);
  y = get(y);
  if (x == y) {
    return;
  }
  if (ts[x] < ts[y]) {
    swap(x, y);
  }
  p[y] = x;
  ts[x] += ts[y];
  for (int i = 0; i < sz(comp[y]); i++) {
    comp[x].push_back(comp[y][i]);
  }
  comp[y].clear();
}

void solve() {
  for (int i = 0; i < n; i++) {
    sort(a[i].begin(), a[i].end());
    cs[i] = make_pair(a[i].empty() ? inf : a[i][0].first, i);
  }
  sort(cs, cs + n);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    ts[i] = 1;
    comp[i].clear();
    comp[i].push_back(c[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < sz(a[i]); j++) {
      if (a[i][j].first + a[i][0].first <= x) {
        unite(a[i][j].second, a[i][0].second);
      }
      if (cs[0].second != i) {
        if (a[i][j].first + a[cs[0].second][0].first <= y) {
          unite(a[cs[0].second][0].second, a[i][j].second);
        }
      } else {
        if (cs[1].first != inf) {
          if (a[i][j].first + a[cs[1].second][0].first <= y) {
            unite(a[cs[1].second][0].second, a[i][j].second);
          }
        }
      }
    }
  }
  int res = 1;
  for (int it = 0; it < n; it++) {
    if (p[it] != it) {
      continue;
    }
    auto &comp = ::comp[it];
    sort(comp.begin(), comp.end());
    res = mul(res, f[ts[it]]);
    for (int r = 0; r < sz(comp);) {
      int l = r;
      while (r < sz(comp) && comp[r] == comp[l]) {
        r++;
      }
      res = mul(res, finv[r - l]);
    }
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 28536