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

typedef pair<int, int> ii;

const int MOD = 1e9+7;
long long fact[200005];

ii CW[200005];

ii colour[200005];
ii colour2[200005];

vector<int> colourList[200005];

// Construct graph
vector<int> AdjList[200005];
bool visited[200005];

// set of integers in different components
multiset<int> component[200005];

long long modPow(long long a, long long b){
    if(b == 0){
        return 1%MOD;
    }else if(b == 1){
        return a%MOD;
    }else{
        long long temp = modPow(a, b>>1);
        if(b&1){
            return (temp*temp)%MOD*a%MOD;
        }else{
            return (temp*temp)%MOD;
        }
    }
}

int main(){
    int N, X, Y;
    scanf("%d%d%d", &N, &X, &Y);

    fact[0] = 1;
    for(int i = 1; i <= N; i ++){
        fact[i] = (fact[i-1]*i)%MOD;
        colour[i] = ii(2147483647, 2147483647);
    }

    for(int i = 0; i < N; i ++){
        int c, w;
        scanf("%d%d", &c, &w);
        CW[i] = ii(c, w);
        colour[c] = min(colour[c], ii(w, i));
        colourList[c].push_back(i);
    }

    for(int c = 1; c <= N; c ++){
        int minIndx = colour[c].second;
        for(int i: colourList[c]){
            if(i != minIndx && CW[i].second+CW[minIndx].second <= X){
                AdjList[i].push_back(minIndx);
                AdjList[minIndx].push_back(i);
                //printf("pushed in: %d %d colour=%d\n", i, minIndx, c);
            }
        }
    }

    for(int i = 1; i <= N; i ++){
        colour2[i] = colour[i];
    }
    sort(colour2+1, colour2+(N+1));

    memset(visited, -1, sizeof(visited));

    for(int k = 1; k < 3; k ++){
        int indx = colour2[k].second;
        if(indx > N){continue;}
        int c = CW[indx].first;

        for(int i = 0; i < N; i ++){
            if(CW[i].first != c){
                // colour is different
                if(CW[i].second + CW[indx].second <= Y){
                    AdjList[i].push_back(indx);
                    AdjList[indx].push_back(i);
                    //printf("pushed in: %d %d\n", i, indx);
                }
            }
        }
    }

    int cnt = 0;
    memset(visited, 0, sizeof(visited));
    for(int i = 0; i < N; i ++){
        if(!visited[i]){
            visited[i] = true;
            queue<int> q;
            q.push(i);
            component[cnt].insert(CW[i].first);
            while(!q.empty()){
                int u = q.front(); q.pop();
                for(int v: AdjList[u]){
                    if(!visited[v]){
                        visited[v] = true;
                        q.push(v);
                        component[cnt].insert(CW[v].first);
                    }
                }
            }
            cnt ++;
        }
    }

    long long ans = 1;
    for(int i = 0; i < cnt; i ++){
        set<int> s;
        //printf("Component %d: ", i);
        for(int j: component[i]){
            //printf("%d ", j);
            s.insert(j);
        }
        //printf("\n");

        ans = ans*fact[component[i].size()]%MOD;

        for(int j: s){
            ans = ans*modPow(fact[component[i].count(j)], MOD-2)%MOD;
        }
    }

    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 51380