#include "bits/stdc++.h"
using namespace std;

#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pll     pair<long long, long long>

static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int INF = 0x3f3f3f3f;
static const int MOD = 1000000007;

struct UnionFind {
        int n;
        vector<int> parent;
        vector<int> rank;
        vector<int> num;
        int find(int x) {
                if (parent[x] == x) return  x;
                return parent[x] = find(parent[x]);
        }
        UnionFind(int n_) {
                n = n_;
                parent.resize(n);
                for (int i = 0; i < n; i ++) parent[i] = i;
                rank.assign(n, 0);
                num.assign(n, 1);
        }
        void unite(int x, int y) {
                if ((x = find(x)) != (y = find(y))) {
                        if (rank[x] < rank[y]) {
                                parent[x] = y;
                                num[y] += num[x];
                        } else {
                                parent[y] = x;
                                if (rank[x] == rank[y]) rank[x] ++;
                                num[x] += num[y];
                        }
                        n --;
                }
        }
        bool same(int x, int y) { return find(x) == find(y); }
        int get() { return n; }
        int get(int x) { return num[find(x)]; }
};

long long inv(long long a) { //フェルマーの小定理と繰り返し2乗法による逆元
        long long res = 1;
        long long n = MOD - 2;
        while (n > 0) {
                if (n & 1) res = res * a % MOD;
                a = a * a % MOD;
                n >>= 1;
        }
        return res;
}
long long fact[202020];

void init() {
        fact[0] = 1;
        for (int i = 1; i < 202020; i ++) fact[i] = fact[i - 1] * i % MOD;
}

void solve() {
        init();
        long long n, x, y;
        cin >> n >> x >> y;
        vector<vector<pll>> color(200000);
        for (int i = 0; i < n; i ++) {
                long long c, w;
                cin >> c >> w;
                color[c - 1].emplace_back(i, w);
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
                if (color[i].size() > 0) cnt ++;
        }
        if (cnt == 1) {
                cout << 1 << endl;
                return;
        }
        vector<pll> ball(n);
        for (int i = 0; i < 200000; i ++) if (!color[i].empty()) {
                sort(all(color[i]), [](const pll &a, const pll &b) { return a.second < b.second; });
                int minwei = color[i][0].second;
                for (int j = 0; j < color[i].size(); j ++) {
                        if (minwei + color[i][j].second <= x) {
                                ball[color[i][j].first] = mp(i, minwei);
                        } else {
                                ball[color[i][j].first] = mp(i, color[i][j].second);
                        }
                }
        }       
//cerr << endl;
//for (int i = 0; i < n; i ++) {
//        cerr << ball[i].first << ' ' << ball[i].second << endl;
//}
        int mi1 = INF, idx1, mi2 = INF, idx2;
        for (int i = 0; i < n; i ++) {
                if (ball[i].second < mi1) {
                        mi1 = ball[i].second;
                        idx1 = i;
                }
        }
        for (int i = 0; i < n; i ++) {
                if (ball[i].first != ball[idx1].first && ball[i].second < mi2) {
                        mi2 = ball[i].second;
                        idx2 = i;
                }
        }
//cerr << mi1 << ' ' << idx1 << ' ' << mi2 << ' ' << idx2 << endl;
        UnionFind uf(n);
        for (int i = 0; i < n; i ++) {
                if (ball[i].second + ball[idx1].second <= y && ball[i].first != ball[idx1].first) {
                        uf.unite(i, idx1);
                }
        }
        for (int i = 0; i < n; i ++) {
                if (ball[i].second + ball[idx2].second <= y && ball[i].first != ball[idx2].first) {
                        uf.unite(i, idx2);
                }
        }
        if (uf.same(idx1, idx2)) {
                int all = uf.get(idx1);
                map<int, int> color_cnt;
                for (int i = 0; i < n; i ++) {
                        if (uf.same(i, idx1)) {
                                color_cnt[ball[i].first] ++;
                        }
                }
                long long ans = fact[all];
                for (auto c : color_cnt) {
                        ans = ans * inv(fact[c.second]) % MOD;
                }
                cout << ans % MOD << endl;
        } else {
                //int all = uf.get(idx1);
                //map<int, int> color_cnt;
                //for (int i = 0; i < n; i ++) {
                //        if (uf.same(i, idx1)) {
                //                color_cnt[ball[i].first] ++;
                //        }
                //}
                //long long ans = fact[all];
                //for (auto c : color_cnt) {
                //        ans = ans * inv(fact[c.second]) % MOD;
                //}
                //all = uf.get(idx2);
                //color_cnt.clear();
                //for (int i = 0; i < n; i ++) {
                //        if (uf.same(i, idx2)) {
                //                color_cnt[ball[i].first] ++;
                //        }
                //}
                //ans = ans * fact[all] % MOD;
                //for (auto c : color_cnt) {
                //        ans = ans * inv(fact[c.second]) % MOD;
                //}
                //cout << ans << endl;
                cout << 1 << endl;
        }
        return;
}

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

        //int T;
        //freopen("a.in", "r", stdin);
        //cin >> T;
        //while (T --) solve();
        
        solve();
        return 0;
}


Measured memory_bytes: 23936