/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl;
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl;
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl;
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl;
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl;
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 200010;

ll n, X, Y;
ppi ar[maxn];
vpii cols[maxn];
ll rt[maxn];
ll fact[maxn], ifact[maxn];
vi comp[maxn];

ll pow_mod(ll a, ll b) {
    ll r = 1;
    while (b) {
        if (b & 1) Mul(r, a);
        Mul(a, a);
        b >>= 1;
    }
    return r;
}

ll root(ll x) {
    return rt[x] == x ? x : rt[x] = root(rt[x]);
}

void MAIN() {

    cin >> n >> X >> Y;
    iota(rt, rt + n, 0);
    fori (i, n) {
        ll c, w; cin >> c >> w; --c;
        cols[c].pb({w, i});
        ar[i] = {{w, c}, i};
    }
    fori (i, n) {
        if (cols[i].empty()) continue;
        pii mn = *min_element(all(cols[i]));
        fori (j, cols[i].size()) {
            if (cols[i][j].F + mn.F <= X) rt[cols[i][j].S] = mn.S;
        }
    }
    sort(ar, ar + n);
    fori (i, n) {
        if (ar[i].F.S != ar[0].F.S && ar[i].F.F + ar[0].F.F <= Y) rt[root(ar[i].S)] = root(ar[0].S);
    }
    ll mn2 = 0;
    while (mn2 < n && ar[mn2].F.S == ar[0].F.S) ++mn2;
    if (mn2 < n) {
        fori (i, n) {
            if (ar[i].F.S != ar[mn2].F.S && ar[i].F.F + ar[mn2].F.F <= Y) rt[root(ar[i].S)] = root(ar[mn2].S);
        }
    }
    fori (i, n) comp[root(ar[i].S)].pb(ar[i].F.S);

    fact[0] = 1;
    fori (i, n) fact[i + 1] = fact[i] * (i + 1) % MOD;
    ifact[n] = pow_mod(fact[n], MOD - 2);
    forir (i, n) ifact[i] = ifact[i + 1] * (i + 1) % MOD;

    ll ans = 1;
    fori (i, n) {
        ll cn = comp[i].size();
        Mul(ans, fact[cn]);
        sort(all(comp[i]));
        ll j = 0;
        while (j < cn) {
            ll k = j;
            while (k < cn && comp[i][j] == comp[i][k]) ++k;
            Mul(ans, ifact[k - j]);
            j = k;
        }
    }
    cout << ans << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(
5 5 100
3 10 
3 10
3 10
3 10
4 10

4 7 3
3 2
4 3
2 1
4 4

21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15
    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 30208