#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

ll inv[1000000];
ll FactorialInv[1000000];
ll Factorial[1000000];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    inv[1] = 1;
    FactorialInv[1] = 1;
    Factorial[1] = 1;
    for(int i = 2; i < 1000000; i++){
        inv[i] = beki(i, mod - 2);
        Factorial[i] = Factorial[i - 1] * i % mod;
        FactorialInv[i] = FactorialInv[i - 1] * inv[i] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};

    map<ll, ll> mp[200005];
    vector<ll> use[200005];
    vector<l_l> balls[200010];
    ll c[200010];
    ll w[200010];

int main() {
    //cout.precision(10);
    init_combination();
    UnionFind uni(200010);
    ll N, X, Y;
    cin >> N >> X >> Y;
    ll min_index;
    for(int i = 1; i <= N; i++) {
        cin >> c[i] >> w[i];
        balls[c[i]].push_back({w[i], i});
        min_index = c[i];
    }
    for(int i = 1; i <= N; i++) {
        //cout << i << endl;
        sort(balls[i].begin(), balls[i].end());
        if(balls[i].empty()) continue;
        if(balls[i][0].first < balls[min_index][0].first) min_index = i;
        for(int j = 1; j < balls[i].size(); j++) {
            if(balls[i][0].first + balls[i][j].first > X) break;
            uni.merge(balls[i][0].second, balls[i][j].second);
        }
    }
    for(int i = 1; i <= N; i++) {
        //cout << i << endl;
        if(i == min_index) continue;
        for(int j = 0; j < balls[i].size(); j++) {
            int now_val = balls[i][j].first;
            int now_index = balls[i][j].second;
            int ok = -1;
            int ng = balls[min_index].size();
            while(ng - ok > 1) {
                int mid = (ok + ng) / 2;
                if(now_val + balls[min_index][mid].first <= Y) ok = mid;
                else ng = mid;
            }
            if(ok == -1) break;
            uni.merge(balls[min_index][ok].second, now_index);
            while(ok >= 1) {
                if(!uni.merge(balls[min_index][ok].second, balls[min_index][ok - 1].second)) break;
                ok--;
            }
        }
    }
    for(int i = 1; i <= N; i++) {
        //cout << uni.root(i) << endl;
    }
    int occupied = 0;
    int inv[200005];
    for(int i = 1; i <= N; i++) {
        inv[i] = -1;
    }
    for(int i = 1; i <= N; i++) {
        int ROOT = uni.root(i);
        if(inv[ROOT] == -1) {
            inv[ROOT] = occupied;
            occupied++;
        }
        int index = inv[ROOT];
        mp[index][c[i]]++;
        use[index].push_back(c[i]);
    }
    //cout << occupied << endl;
    ll ans = 1;
    for(int check = 0; check < occupied; check++) {
        sort(use[check].begin(), use[check].end());
        use[check].erase(unique(use[check].begin(), use[check].end()), use[check].end());
        ll sum = 0;
        for(int i = 0; i < use[check].size(); i++) {
            int now = mp[check][use[check][i]];
            ans = (ans * FactorialInv[now]) % mod;
            sum += now;
        }
        ans = (ans * Factorial[sum]) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 73216