#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

const int limit=200010;
int c[limit],w[limit];

struct Union_find{
	Union_find(int n){par.resize(n),iota(_all(par),0);}
	int find(int x){return (par[x]==x)?x:par[x]=find(par[x]);}
	void unite(int a,int b){a=find(a),b=find(b);par[a]=b;}
	bool same(int a,int b){return find(a)==find(b);}
	vector<int> par;
};

using pii=pair<int,int>;
vector<pii> color[limit];
map<int,int> group[limit];

template<int MOD> struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt(): x(0){}
	ModInt(signed sig) {int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int getval() const { return int(x); }
	inline int extgcd(int a,int b,int& x,int& y){x=1,y=0;int g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}


	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = 1LL * x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { int y,d; extgcd(that.x,MOD,y,d); return x = 1LL * x * y % MOD; return *this;}
	
	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
};

using mint=ModInt<1000000007>;

mint I[1000010];
void inv_table(int n){I[1]=1LL;rep(i,2,n+1) I[i]=I[mint::Mod%i]*(mint::Mod-mint::Mod/i);}

mint F[1000010],IF[1000010];
void fact_table(int n){F[0]=IF[0]=1LL; rep(i,1,n+1) F[i]=F[i-1]*i,IF[i]=IF[i-1]*I[i];}

int main(void){
	int n,x,y;
	cin >> n >> x >> y;
	rep(i,n) cin >> c[i] >> w[i],c[i]--;

	rep(i,n) color[c[i]].emplace_back(pii(w[i],i));
	rep(i,n) sort(begin(color[i]),end(color[i]));

	Union_find uf(n);
	vector<pii> tar;

	rep(i,n){
		if(color[i].size()==0) continue;
		const int wmin=color[i][0].first,idx=color[i][0].second;
		for(auto &it:color[i]){
			if(wmin+it.first<=x) 
				uf.unite(idx,it.second);
		}
		tar.push_back(pii(wmin,i));
	}

	sort(begin(tar),end(tar));

	const int m=min<int>(2,tar.size());
	rep(i,m){
		const int ww=tar[i].first,cc=tar[i].second;
		rep(j,n){
			if(c[j]==cc) continue;
			if(ww+w[j]<=y) uf.unite(color[cc][0].second,j);
		}
	}

	rep(i,n) group[uf.find(i)][c[i]]++;

	inv_table(n),fact_table(n);
	mint ans(1);

	rep(i,n){
		if(group[i].size()==0) continue;
		int sum=0;
		for(auto &it:group[i]) sum+=it.second;
		mint cur=F[sum];
		for(auto &it:group[i]) cur*=IF[it.second];
		ans*=cur;
	}

	cout << ans.getval() << endl;
	return 0;
}

Measured memory_bytes: 43380