#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

struct perm {
private:
	int sz;
	vector<ll> p, invp;
public:
	perm(int n) {
		sz = n + 1;
		p.resize(sz), invp.resize(sz);
		p[0] = 1;
		rep1(i, sz - 1) {
			p[i] = p[i - 1] * i%mod;
		}
		invp[sz - 1] = 1;
		ll cop = mod - 2, x = p[sz - 1];
		while (cop) {
			if (cop % 2)invp[sz - 1] = invp[sz - 1] * x%mod;
			cop >>= 1; x = x * x % mod;
		}
		per(i, sz - 1) {
			invp[i] = invp[i + 1] * (i + 1) % mod;
		}
	}
	ll comb(ll x, ll y) {
		if (x < y || y < 0)return 0;
		ll ret = p[x];
		(ret *= invp[y]) %= mod;
		(ret *= invp[x - y]) %= mod;
		return ret;
	}
	ll combP(ll x, ll y) {
		if (x < y || y < 0)return 0;
		return p[x] * invp[x - y] % mod;
	}
};
ll mod_pow(ll x, ll n = mod - 2) {
	ll ret = 1;
	while (n) {
		if (n % 2)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}
perm p(1 << 18);

struct uf {
private:
	vector<int> par, ran;
public:
	void init(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		rep(i, n) {
			par[i] = i;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (ran[x] == ran[y])ran[x]++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

vector<int> loc[1 << 18];
int cnt[1 << 18];

void solve() {
	int n, x, y; cin >> n >> x >> y;
	vector<int> c(n), w(n);
	rep(i, n) {
		cin >> c[i] >> w[i];
		loc[c[i]].push_back(i);
	}
	vector<P> v;
	rep(i, n)v.push_back({ w[i],i });
	sort(v.begin(), v.end());
	uf u; u.init(n+1);
	int root = v[0].second;
	int memo = -1;
	int col = c[root];
	bool f = false;
	rep1(i, n - 1) {
		int id = v[i].second;
		if (!f) {
			if (c[id] != col) {
				rep(j, i) {
					if (v[j].first + v[i].first <= y) {
						u.unite(v[j].second, v[i].second);
					}
				}
				f = true; memo = i;
			}
		}
		else {
			if (c[id] == col) {
				if (v[i].first + v[memo].first <= y) {
					u.unite(v[i].second, v[memo].second);
				}
			}
			else {
				if (v[0].first + v[i].first <= y) {
					u.unite(v[0].second, v[i].second);
				}
			}
		}
	}

	rep1(i, n) {
		vector<P> vv;
		rep(j, loc[i].size()) {
			vv.push_back({ w[loc[i][j]],loc[i][j] });
		}
		sort(vv.begin(), vv.end());
		rep(j, vv.size()) {
			if (vv[j].first + vv[0].first <= x) {
				u.unite(vv[0].second, vv[j].second);
			}
		}
	}
	ll ans = 1;
	int tmp = 0;
	rep(i, n) {
		if (u.same(root, i)) {
			tmp++;
			cnt[c[i]]++;
		}
	}
	ans = p.combP(tmp, tmp);
	rep1(i, n) {
		if (cnt[i] == 0)continue;
		ll r = p.combP(cnt[i], cnt[i]); r = mod_pow(r);
		ans = ans * r%mod;
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}

Measured memory_bytes: 20592