#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

class Union_Find {
    public:
    std::vector<int> par;
    Union_Find() {}
    Union_Find(int n){
        par.resize(n, 0);
        for(int i = 0; i < n; i++){
            par[i] = i;
        }
    }

    void simplify(int x) {
        std::vector<int> path;
        while (par[x] != x) {
            path.push_back(x);
            x = par[x];
        }
        for (int p : path) {
            par[p] = x;
        }
    }
    
    int find(int x){
        simplify(x);
        return par[x];
    }
    
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x != y) {
            par[y] = x;
            // 改造する時は「根になっているノードの親を変更する」という原則が守られていることに注意。
        }
    }
};

long long pow_mod(long long x, long long n, long long mod_num) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) { res = (res * x) % mod_num; }
        x = (x * x) % mod_num;
        n = (n >> 1);
    }
    return res;
}

class Combi_Num {
    public:
    long long mod_num;
    std::vector<long long> factorial, factorial_inv, inv;
    Combi_Num() {}
    Combi_Num(const int n, const long long mod_num_in) {
        mod_num = mod_num_in;
        factorial.resize(n+1, 0);
        factorial_inv.resize(n+1, 0);
        inv.resize(n+1, 0);
        factorial[0] = 1;
        factorial_inv[0] = 1;
        inv[0] = 1;
        for (int i = 1; i <= n; i++) {
            factorial[i] = (factorial[i-1] * i) % mod_num;
            inv[i] = pow_mod(i, mod_num - 2, mod_num);
            factorial_inv[i] = (factorial_inv[i-1] * inv[i]) % mod_num;
        }
    }

    long long combi(const int n, const int r) {
        return (factorial[n] * ((factorial_inv[r] * factorial_inv[n-r]) % mod_num)) % mod_num;
    }

    long long perm(const int n, const int r) {
        return (factorial[n] * factorial_inv[n-r]) % mod_num;
    }
};

const int MAX_N = 200050;
int N;
int X, Y, c[MAX_N], w[MAX_N];
long long MOD = 1000000007;

Combi_Num combi_num = Combi_Num(MAX_N, MOD);
std::vector<int> cv[MAX_N];
Union_Find uf = Union_Find(MAX_N);
std::map<int, int> count[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N >> X >> Y;
    for (int i = 1; i <= N; i++) {
        std::cin >> c[i] >> w[i];
    }

    for (int i = 1; i <= N; i++) {
        cv[c[i]].push_back(i);
    }

    std::vector<int> colors;
    for (int i = 1; i <= N; i++) {
        if (0 < cv[i].size()) {
            colors.push_back(i);

            std::sort(cv[i].begin(), cv[i].end(), 
                [](const int a, const int b) { return w[a] < w[b]; }
            );

            for (int j = 1; j < cv[i].size(); j++) {
                if (w[cv[i][0]] + w[cv[i][j]] <= X) {
                    uf.unite(cv[i][0], cv[i][j]);
                }
            }
        }
    }

    std::sort(colors.begin(), colors.end(),
        [](const int a, const int b) { return w[cv[a][0]] < w[cv[b][0]]; }
    );

    for (int j = 1; j < colors.size(); j++) {
        if (w[cv[colors[0]][0]] + w[cv[colors[j]][0]] <= Y) {
            uf.unite(cv[colors[0]][0], cv[colors[j]][0]);
        }
    }

    for (int i = 0; i < std::min((int)colors.size(), 2); i++) {
        for (int j = 1; j <= N; j++) {
            if (c[j] != colors[i]) {
                if (w[j] + w[cv[colors[i]][0]] <= Y) {
                    uf.unite(j, cv[colors[i]][0]);
                }
            }
        }
    }

    for (int i = 1; i <= N; i++) {
        count[uf.find(i)][c[i]]++;
    }

    long long ret = 1;
    for (int i = 1; i <= N; i++) {
        long long sum = 0;
        long long inv = 1;
        for (auto itr = count[i].begin(); itr != count[i].end(); ++itr) {
            sum += itr->second;
            inv = (inv * combi_num.factorial_inv[itr->second]) % MOD;
        }

        ret = (ret * combi_num.factorial[sum]) % MOD;
        ret = (ret * inv) % MOD;
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 35572