//#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = (int) 2e5 + 5;
const int mod = (int) 1e9 + 7;

inline int binpow (int a, int b) {
        int r = 1;
        while (b) {
                if (b & 1) {
                        r = (r * 1LL * a) % mod;
                }
                a = (a * 1LL * a) % mod;
                b >>= 1;
        }
        return r;
}

vector<int> v[N];
int n, x, y, r[N], ans = 1, f[N], fs[N], sz, csz, rf[N];

inline void solve () {
        scanf ("%d%d%d", &n, &x, &y);
        for (int i = 1; i <= n; i++) {
                int c, w;
                scanf ("%d%d", &c, &w);
                v[c].emplace_back (w);
        }
        for (int i = 1; i <= n; i++) {
                if (!v[i].empty ()) {
                        fs[++sz] = i;
                        sort (v[i].begin (), v[i].end ());
                        int L = 1, R = v[i].size () - 1;
                        while (L <= R) {
                                int M = (L + R) >> 1;
                                if (v[i][M] + v[i][0] <= x) {
                                        r[i] = M;
                                        L = M + 1;
                                } else {
                                        R = M - 1;
                                }
                        }
                }
        }
        sort (fs + 1, fs + sz + 1, [] (int first, int second) {return v[first][0] < v[second][0];});
        for (int it = 2; it <= sz; it++) {
                int i = fs[it];
                int L = 1, R = v[i].size () - 1, curr = 0;
                while (L <= R) {
                        int M = (L + R) >> 1;
                        if (v[i][M] + v[fs[1]][0] <= y) {
                                curr = M;
                                L = M + 1;
                        } else {
                                R = M - 1;
                        }
                }
                r[i] = max (r[i], curr) + 1;
//                printf ("%d %d\n", i, r[i]);
        }
        if (sz > 1 && y >= v[fs[1]][0] + v[fs[2]][0]) {
                int L = 1, R = v[fs[1]].size () - 1, curr = 0;
                while (L <= R) {
                        int M = (L + R) >> 1;
                        if (v[fs[1]][M] + v[fs[2]][0] <= y) {
                                curr = M;
                                L = M + 1;
                        } else {
                                R = M - 1;
                        }
                }
                r[fs[1]] = max (r[fs[1]], curr) + 1;
        }
        ans = rf[r[fs[1]]];
        for (int i = 1; i <= n; i++) {
                if (!v[i].empty () && i != fs[1]) {
                        if (v[i][0] + v[fs[1]][0] <= y) {
                                r[fs[1]] += r[i];
                                ans = (ans * 1LL * rf[r[i]]) % mod;
                        }
                }
        }
        ans = (ans * 1LL * f[r[fs[1]]]) % mod;
        printf ("%d\n", ans);
}

int tests = 1;

int main () {
//        freopen (".in", "r", stdin);
//        freopen (".out", "w", stdout);
        f[0] = rf[0] = 1;
        for (int i = 1; i < N; i++) {
                f[i] = (f[i - 1] * 1LL * i) % mod;
                rf[i] = binpow (f[i], mod - 2);
        }
//        scanf ("%d", &tests);
        while (tests--) {
                solve ();
        }
        return 0;
}


Measured memory_bytes: 12160