#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans
template <uint MD>
struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1)
                r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    /*
    M inv() const {
        long long b = MD, u = 1, v = 0;
        long long a = (*this).v;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MD;
        if (u < 0)
            u += MD;
        return M{u};
    }
    */
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
    friend istream& operator>>(istream& is, M& r) { return is >> r.v; }
};
using Mint = ModInt<MOD>;
const int MN = 1000000;
Mint fact[MN], iFac[MN];

void first() {
    fact[0] = Mint(1);
    for (int i = 1; i < MN; i++)
        fact[i] = fact[i - 1] * Mint(i);
    iFac[MN - 1] = fact[MN - 1].inv();
    for (int i = MN - 1; i >= 1; i--) {
        iFac[i - 1] = iFac[i] * Mint(i);
    }
    assert(fact[2345] * iFac[2345] == Mint(1));
}
Mint C(int n, int k) {
    if (n < k || k < 0)
        return Mint(0);
    return fact[n] * iFac[k] * iFac[n - k];
}
//UnionFind
//How to use
//unite(x,y) : 集合 x と y を併合する. 併合済のとき false, 未併合のとき true が返される
//find(k) : 要素 k が属する集合を求める
//size(k) : 要素 k が属する集合の要素の数を求める
struct UnionFind {
    vector<int> data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};


int N, X, Y;
vector<pair<int, int>> V[202020];
int cnt[202020];
int clr[202020];

void solve() {
    first();
    pair<int, int> MIN{INF, -1}, MIN2{INF, -1};
    int MIN_c = 0;
    for (int i = 0; i < N; i++) {
        if (V[i].size())
            if (MIN > V[i][0]) {
                MIN2 = MIN;
                MIN = V[i][0];
                MIN_c = i;
            } else
                chmin(MIN2, V[i][0]);
    }
    cerr << MIN.first << " " << MIN.second << endl;
    cerr << MIN2.first << " " << MIN2.second << endl;
    UnionFind uf(N);

    for (int i = 0; i < N; i++) {
        auto& v = V[i];
        if (v.size()) {
            if (i != MIN_c) {
                for (auto& p : v) {
                    if (p.first + MIN.first <= Y)
                        uf.unite(p.second, MIN.second);
                    else
                        break;
                }
            } else {
                for (auto& p : v) {
                    if (p.first + MIN2.first <= Y)
                        uf.unite(p.second, MIN.second);
                    else
                        break;
                }
            }
            auto MIN = v[0];
            for (auto& p : v) {
                if (p.first + MIN.first <= X)
                    uf.unite(p.second, MIN.second);
                else
                    break;
            }
        }
    }

    Mint ans = 1;
    map<int, map<int, int>> mp;
    int tot[202020] = {};
    for (int i = 0; i < N; i++) {
        mp[uf.find(i)][clr[i]]++;
        tot[uf.find(i)]++;
    }
    for (auto& p : mp) {
        auto m = p.second;
        ans *= fact[tot[p.first]];
        //cerr << tot[p.first] << endl;
        for (auto& pp : m) {
            ans *= iFac[pp.second];
            //cerr << "->" << pp.first + 1 << " " << pp.second << endl;
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N >> X >> Y;
    for (int i = 0; i < N; i++) {
        int c, w;
        cin >> c >> w;
        c--;
        V[c].push_back(make_pair(w, i));
        clr[i] = c;
    }
    for (int i = 0; i < N; i++) {
        sort(all(V[i]));
    }

    solve();
    return 0;
}


Measured memory_bytes: 56604