#include <iostream>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

struct TBall {
    int c, w, id;
};

bool comp_cw(TBall x, TBall y) {
    return mt(x.c, x.w, x.id) < mt(y.c, y.w, y.id);
}

bool comp_wc(TBall x, TBall y) {
    return mt(x.w, x.c, x.id) < mt(y.w, y.c, y.id);
}

const int maxn = 210000;
const i64 P = 1000000000 + 7;
TBall a[maxn];
i64 fact[maxn], tcaf[maxn];

i64 deg(i64 x, i64 d) {
    d %= P - 1;
    if (d < 0) d += P - 1;
    i64 y = 1;
    while (d) {
        if (d & 1) y *= x, y %= P;
        x *= x, x %= P;
        d /= 2;
    }
    return y;
}

vi e[maxn];
int vis[maxn];
void add_edge(int v, int u) {
    e[v].pb(u); e[u].pb(v);
}

void dfs(int v, vector<TBall> &comp) {
    if (vis[v]) return;
    vis[v] = 1;
    comp.pb(a[v]);
    for (int u: e[v]) dfs(u, comp);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, x, y;
    cin >> n >> x >> y;
    fact[0] = 1; for1(i, n) fact[i] = fact[i - 1] * i % P;
    forn(i, n + 1) tcaf[i] = deg(fact[i], -1);

    forn(i, n) cin >> a[i].c >> a[i].w, a[i].id = i;
    vector<TBall> b(a, a + n);
    sort(all(b), comp_cw);
    int l = 0;
    while (l < n) {
        int r = l;
        while (r < n && b[l].c == b[r].c) ++r;
        forn(i, r - l) if (b[l].w + b[l + i].w <= x) add_edge(b[l].id, b[l + i].id);
        l = r;
    }

    sort(all(b), comp_wc);
    vector<TBall> bs;
    for (auto w: b) {
        bool ok = true;
        for (auto ww: bs) ok &= w.c != ww.c;
        if (ok) bs.pb(w);
        if (bs.size() > 10) break;
    }

    for (auto w: b) {
        for (auto ww: bs) {
            if (w.c != ww.c) {
                if (w.w + ww.w <= y) add_edge(w.id, ww.id);
                break;
            }
        }
    }

    i64 ans = 1;
    forn(i, n) {
        if (vis[i]) continue;
        vector<TBall> comp;
        dfs(i, comp);
        sort(all(comp), comp_cw);
        ans *= fact[comp.size()]; ans %= P;
        int l = 0;
        while (l < comp.size()) {
            int r = l;
            while (r < comp.size() && comp[l].c == comp[r].c) ++r;
            ans *= tcaf[r - l]; ans %= P;
//            forn(i, r - l) if (b[l].w + b[l + i].w <= x) add_edge(b[l].id, b[l + i].id);
            l = r;
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 25200