#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7
using ar3=array<ll,3>;

class UnionFind {
public:
	vector<int>rank, parent;
	UnionFind(int size) {
		rank.resize(size, 0);
		parent.resize(size, 0);
		REP(i, size)parent[i] = i;
	}
	int find(int x) {
		if (parent[x] == x)return x;
		else return parent[x] = find(parent[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y])
			parent[x] = y;
		else {
			parent[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	bool same(int x, int y) {
		return (find(x) == find(y));
	}
};

struct COMB {
	static constexpr ll LIM = 201'000;
	COMB(){
		make_contents();
	}

	//in:  x,n,mod
	//out: x^n(Mod mod)
	ll mod_pow(ll x, ll n, ll mod) const {
		ll res = 1;
		while (n > 0) {
			if (n & 1)res = (res * x) % mod;
			x = (x * x) % mod;
			n >>= 1;
		}
		return res;
	}

	void make_contents()
	{
		ll tmp = 1;
		fact.push_back(0);
		FOR(i, 1, LIM) {
			tmp *= i;
			tmp %= MOD;
			fact.push_back(tmp);
		}

		tmp = mod_pow(tmp, MOD - 2, MOD);
		//inv.push_back(tmp);
		for (ll i = LIM - 1; i > 0; i--) {
			tmp *= i;
			tmp %= MOD;
			inv.push_back(tmp);
		}
		reverse(inv.begin(), inv.end());
		fact[0] = inv[0] = 1;
	}

	ll comb(ll n, ll k) {
		ll res = fact[n];
		res *= inv[k]; res %= MOD;
		res *= inv[n - k]; res %= MOD;
		return res;
	}

	vector<ll> fact, inv;
};

map<ll,vector<pair<ll,ll>>> set_color(vector<pair<ll,ll>>& cw){
	map<ll,vector<pair<ll,ll>>> mp;
	REP(i,cw.size()){
		ll color = cw[i].first;
		ll weight = cw[i].second;
		mp[color].push_back({weight,i});
	}	
	for(auto& p: mp){
		sort(p.second.begin(), p.second.end());
	}
	return mp;
}

void unite_same(
	const ll X,
	vector<pair<ll,ll>>& v, 
	UnionFind& uf
){
	auto itr=v.begin();
	ll base = itr->first;
	ll idx = itr->second;

	while(++itr!=v.end()){
		ll weight = itr->first;
		ll opp = itr->second;	
		if(base + weight>X) break;
		uf.unite(idx,opp);
	}
}

vector<pair<ll,ll>> get_minimums(map<ll,vector<pair<ll,ll>>>& mp){
	vector<pair<ll,ll>> res;
	for(auto& p:mp){
		res.push_back(p.second.front());
	}	
	sort(res.begin(),res.end());
	return res;
}

map<ll, map<ll,ll>> count_color(
	const vector<pair<ll,ll>>& cw,
	UnionFind& uf
){
	map<ll, map<ll,ll>> res;
	REP(i,cw.size()){
		ll parent = uf.find(i);
		res[parent][cw[i].first]++;
	}	
	return res;
}

vector<ar3> get_minimums(vector<pair<ll,ll>>& cw){
	vector<ar3> res;
	REP(i,cw.size()){
		res.push_back({cw[i].second, cw[i].first, i});
	}
	sort(res.begin(),res.end());
	return res;
}

void unite_diff(
	const vector<pair<ll,ll>>& cw,
	const ll Y,
	UnionFind& uf,
	ar3 mine
){
	ll baseWeight=mine[0];
	ll baseColor=mine[1];
	ll baseIdx=mine[2];
	REP(i,cw.size()){
		if(cw[i].first==baseColor)continue;
		if(cw[i].second + baseWeight>Y)continue;
		uf.unite(i, baseIdx);
	}
}

void unite_subdiff(
	const vector<pair<ll,ll>>& cw,
	const ll Y,
	UnionFind& uf,
	vector<ar3>& mines
){
	ll tgtColor = mines[0][1];
	ll baseWeight = mines[1][0];
	ll baseIdx = mines[1][2];
	REP(i,cw.size()){
		if(cw[i].first != tgtColor) continue;
		if(cw[i].second + baseWeight > Y)continue;
		uf.unite(i, baseIdx);
	}
}

ll maccumulate(const COMB& comb, map<ll,ll>& mp){
	vector<ll> info;
	for(auto p:mp)info.push_back(p.second);	

	ll all = accumulate(info.begin(),info.end(), 0ll);
	ll res = comb.fact[all];
	for(auto num:info){
		(res*=comb.inv[num])%=MOD;	
	}
	return res;
}

int main()
{
	ll N,X,Y;
	cin>>N>>X>>Y;
	if(N==1){
		cout<<1<<endl;
		return 0;
	}

	UnionFind uf(N);
	vector<pair<ll,ll>> cw(N);
	REP(i,N) cin >> cw[i].first >> cw[i].second;

	auto color_info = set_color(cw);
	for(auto p: color_info){
		unite_same(X, p.second, uf);
	}

	auto mines = get_minimums(cw);
	unite_diff(cw, Y, uf, mines[0]);
	unite_subdiff(cw, Y, uf, mines);

	ll res=1;
	COMB comb;
	auto count = count_color(cw, uf);
	for(auto p:count){
		(res*=maccumulate(comb, p.second))%=MOD;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 60908