#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


const int max_comb=210000;
vector<ll> fac(max_comb+1); //n! (mod M)
vector<ll> ifac(max_comb+1); //k!^(-1) (mod M)

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x){
    return mpow( x, MOD-2 );
}

ll comb(int a, int b){     // C(a,b) = a! * b!^(-1) * (a-b)^(-1)
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

ll perm(int a, int b){     // P(a,b) = a! * (a-b)!^(-1)
    if(b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b] % MOD;
    return tmp * fac[a] % MOD;
}

void pre_comb()
{
    fac[0] = 1;
    ifac[0] = 1;
    for(int i = 0; i<max_comb; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*minv(i+1) % MOD; // k!^(-1) (mod M)
    }
    return;
}

class UF
{
private:
    int         num;
    vector<int> par;
    vector<int> siz;
public:
    //vector<int> val;
public:
    UF(int n): num(n) {
        par.resize(n);
        siz.resize(n);
        //val.resize(n);
        int i;
        for(i=0; i<n; i++) {
            par[i]=i; siz[i]=1;
            //val[i]=0;
        }
    }
	
    int find(int x) {
        if(x==par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(siz[x]<siz[y]) {
            par[x]=y;
            siz[y]=siz[x]+siz[y];
            //val[y]=val[x]+val[y];
        }
        else {
            par[y]=x;
            siz[x]=siz[x]+siz[y];
            //val[x]=val[x]+val[y];
        }
    }

    bool same(int x, int y) {
        return find(x)==find(y);
    }

    int size(int x) {
        return siz[find(x)];
    }

    int ngroup() {
    //int ngroup( int& ans ) {
        int count=0;
        int i;
        for(i=0; i<num; i++) {
            if(par[i]==i) {
                count++;
                //ans += (val[i]? siz[i]: siz[i]-1);
            }
        }
        return count;
    }
};

void solve()
{
    pre_comb();

    int n; ll x, y;
    scanf("%d%lld%lld", &n, &x, &y);
    vector<vector<pair<ll,int> > > vv(n);
    vector<int> c(n);
    int i, j;
    for (i = 0; i < n; i++) {
        ll w;
        scanf("%d%lld", &c[i], &w); c[i]--;
        vv[c[i]].push_back(make_pair(w, i));
    }
    vector<pair<ll, int> > z;
    for (i = 0; i < n; i++) {
        sort(vv[i].begin(), vv[i].end());
        if (!vv[i].empty()) {
            z.push_back(make_pair(vv[i][0].first, i));
        }
    }
    sort(z.begin(), z.end());

    UF uf(n);
    for (i = 0; i < n; i++) {
        int num = (int)vv[i].size();
        if (num < 2) continue;

        for (j = 1; j < num; j++) {
            if (vv[i][0].first + vv[i][j].first <= x) {
                uf.unite(vv[i][0].second, vv[i][j].second);
            }
        }
    }

    if ((int)z.size() > 1) {
        for (i = 0; i < n; i++) {
            int num = (int)vv[i].size();
            if (num < 1) continue;

            ll base_val = z[0].first;
            int base_id = vv[z[0].second][0].second;
            if (i == z[0].second) {
                base_val = z[1].first;
                base_id = vv[z[1].second][0].second;
            }

            for (j = 0; j < num; j++) {
                if (base_val + vv[i][j].first <= y) {
                    uf.unite(base_id, vv[i][j].second);
                }
            }
        }
    }

    vector<vector<int> > v(n);
    for (i = 0; i < n; i++) {
        v[uf.find(i)].push_back(i);
    }

    ll ans = 1;
    for (i = 0; i < n; i++) {
        vector<int>& v0 = v[i];
        int num = (int)v0.size();
        if (num < 2) continue;

        map<int, int> cnt;
        for (j = 0; j < num; j++) {
            cnt[c[v0[j]]]++;
        }

        ll ans0 = 1;
        int numcurr = num;
        auto it=cnt.begin();
        for (; it != cnt.end(); ++it) {
            int tmp=it->second;
            ans0 = ans0 * comb(numcurr, tmp) % MOD;
            numcurr -= tmp;
        }
        ans = ans * ans0%MOD;
    }
    printf("%lld\n", ans);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 31856