#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

long long min(long long a, long long b) {return a < b ? a : b;}
long long min(int a, long long b) {return a < b ? a : b;}
long long min(long long a, int b) {return a < b ? a : b;}
long long min(int a, int b) {return a < b ? a : b;}

long long max(long long a, long long b) {return a > b ? a : b;}
long long max(int a, long long b) {return a > b ? a : b;}
long long max(long long a, int b) {return a > b ? a : b;}
long long max(int a, int b) {return a > b ? a : b;}

#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const int N = 500000;
const int MOD = 1e9 + 7;
const double eps = 1e-8;

int n, X, Y, ans = 1;
long long c[N], w[N];
vector<pii> pos[N];
vector<int> graph[N];
vector<pii> opt;
set<int> ss;
int cnt[N];
int color[N];
int f[N], ufact[N], r[N];

void dfs(int v)
{
    if (color[v] == 1) return;
    color[v] = 1;
    cnt[c[v]]++; ss.insert(c[v]);
    for (auto u : graph[v]) dfs(u);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    r[1] = 1;
    for (int i = 2; i < N; i++) r[i] = MOD - r[MOD % i] * (MOD / i) % MOD;
    f[0] = 1, ufact[0] = 1;
    for (int i = 1; i < N; i++) f[i] = f[i - 1] * i % MOD, ufact[i] = ufact[i - 1] * r[i] % MOD;
    cin >> n >> X >> Y;
    for (int i = 0; i < n; i++) cin >> c[i] >> w[i], c[i]--, pos[c[i]].push_back({w[i], i});
    for (int i = 0; i < n; i++)
    {
        int mn2 = 2e9 + 111, id2 = -1;
        for (int j = 0; j < pos[i].size(); j++) if (pos[i][j].first < mn2) mn2 = pos[i][j].first, id2 = pos[i][j].second;
        for (int j = 0; j < pos[i].size(); j++)
        {
            if (pos[i][j].first + mn2 <= X) graph[pos[i][j].second].push_back(id2), graph[id2].push_back(pos[i][j].second);
        }
        if (id2 != -1) opt.push_back({mn2, id2});
    }
    int mn = 2e9 + 111, id = -1;
    for (int j = 0; j < opt.size(); j++) if (opt[j].first < mn) mn = opt[j].first, id = opt[j].second;
    int mn1 = 2e9 + 111, id1 = -1;
    for (int j = 0; j < opt.size(); j++) if (opt[j].first < mn1 && opt[j].second != id) mn1 = opt[j].first, id1 = opt[j].second;
    for (int i = 0; i < n; i++)
    {
        if (c[i] != c[id])
        {
            if (w[i] + mn <= Y) graph[i].push_back(id), graph[id].push_back(i);
        }
        if (c[i] != c[id1])
        {
            if (w[i] + mn1 <= Y) graph[i].push_back(id1), graph[id1].push_back(i);
        }
    }
    for (int i = 0; i < n; i++)
    {
        dfs(i);
        int sz = 0;
        for (auto it : ss)
        {
            sz += cnt[it];
            ans = ans * ufact[cnt[it]] % MOD;
            cnt[it] = 0;
        }
        ans = ans * f[sz] % MOD;
        ss.clear();
    }
    cout << ans;
}


Measured memory_bytes: 75588