#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

class Combination
{
public:

    vec fact, invfact;
    int MAX_N, mod;

    Combination(int MAX_N, int mod): MAX_N(MAX_N), mod(mod) {
        initialize();
    }

    void initialize(){
        fact = vec(MAX_N + 1);
        invfact = vec(MAX_N + 1);
        fact[0] = 1;
        FOR(i, 1, MAX_N + 1){
            fact[i] = (fact[i - 1] * i) % mod;
        }
        invfact[MAX_N] = fastpow(fact[MAX_N], mod - 2, mod);
        IREP(i, MAX_N){
            invfact[i] = (invfact[i + 1] * (i + 1)) % mod;
        }
    }

    int nCr(int n, int r){
        if(r > n || r < 0 || n < 0) return 0;
        if(n > MAX_N){
            MAX_N = n;
            initialize();
        }
        int a = fact[n];
        a = (a * invfact[r]) % mod;
        a = (a * invfact[n - r]) % mod;
        return a;
    }
};

signed main(){

    int mod = 1000000007;
    int N, X, Y; cin >> N >> X >> Y;
    vec c(N), w(N);
    REP(i, N){
        cin >> c[i] >> w[i];
        c[i]--;
    }

    vec c_min(N, INF);
    int min1 = INF, min2 = INF, c1, c2;
    REP(i, N){
        c_min[c[i]] = min(c_min[c[i]], w[i]);
        if(w[i] < min1){
            min2 = min1;
            c2 = c1;
            min1 = w[i];
            c1 = c[i];
        }else if(w[i] < min2){
            min2 = w[i];
            c2 = c[i];
        }
    }

    //他色と交換できるか
    vector<bool> c_movable1(N, false), c_movable2(N, false);
    REP(i, N){
        if(i == c1 && c_min[i] + min2 <= Y) c_movable1[i] = true;
        if(i != c1 && c_min[i] + min1 <= Y) c_movable1[i] = true;
        if(c[i] == c1 && w[i] + min2 <= Y) c_movable2[i] = true;
        if(c[i] != c1 && w[i] + min1 <= Y) c_movable2[i] = true;
    }
    //自色と交換できるか
    vector<bool> n_movable(N, false);
    REP(i, N) if(w[i] + c_min[c[i]] <= X) n_movable[i] = true;

    //各色で動かせる個数
    vec N_movable(N, 0);
    int tot = 0;
    REP(i, N) if(c_movable2[i] || (c_movable1[c[i]] && n_movable[i])){
        N_movable[c[i]]++;
        tot++;
    }

    Combination C(N, mod);
    int ans = 1;
    REP(i, N){
        ans *= C.nCr(tot, N_movable[i]);
        tot -= N_movable[i];
        ans %= mod;
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 9728