#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T> T expo(T base, T e, T mod) { T res = 1;
  while(e > 0) { if(e&1) res = res * base % mod; base = base * base % mod; e >>= 1; }
  return res;
}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}
#define gc getchar_unlocked
template <typename T> void in(T &x) {
	T c = gc(); while(((c < 48) || (c > 57)) && (c!='-')) c = gc();
	bool neg = false; if(c == '-') neg = true; x = 0; for(;c < 48 || c > 57;c=gc());
	for(;c > 47 && c < 58;c=gc())	x = (x*10) + (c - 48); if(neg)	x = -x;
}

const int MAXN = 4e5 + 3;
LL fact[MAXN] = {0}, ifact[MAXN] = {0};
void preprocess() {
	fact[0] = (ifact[0] = 1);
    for(int i = 1; i < MAXN; i++) {
		fact[i] = (fact[i-1]*i)%mod;
	}
	ifact[MAXN-1] = modinv(fact[MAXN-1], mod); ifact[0] = 1;
	for(LL i = MAXN-2; i > 0; i--){
		ifact[i] = (ifact[i+1]*(i+1))%mod;
	}
	assert((fact[2]*ifact[2])%mod == 1);
}
LL nCr(int n, int r) {
    return (fact[n] * ((ifact[n-r] * ifact[r])%mod)) % mod;
}
struct dsu {
  vector<int> Rank, P;
  int V;
  dsu(int v = 0) : V(v) {
    Rank = vector<int>(v + 1, 0);
    P = vector<int>(v + 1, 0);
    for(int i = 0; i < P.size(); i++) {
      P[i] = i, Rank[i] = 1;
    }
  }
  int find_root(int x) { return x == P[x] ? x : P[x] = find_root(P[x]); }
  void merge(int x, int y) {
    int xr = find_root(P[x]), yr = find_root(P[y]);
    if(xr == yr) return ;
    if(Rank[xr] < Rank[yr]) swap(xr, yr), swap(x, y);
    Rank[xr] += Rank[yr];
    P[yr] = xr;
  }
};

const LL INF = 1e10 + 1;
int n;
LL X, Y;
LL colors[MAXN], wts[MAXN];
vector<pair<LL, int> > adj[MAXN];
vector<pair<LL, int> > total;
vector<int> in_that[MAXN];
LL cnt[MAXN];
LL col_min[MAXN];
int indices[MAXN];

int main() {
	preprocess();
	in(n), in(X), in(Y);
	dsu tester(n + 1);
	for(int i = 1; i <= n; i++) {
		col_min[i] = INF;
		in(colors[i]), in(wts[i]);
		adj[colors[i]].push_back({wts[i], i});
		// total.push_back({wts[i], i});
	}
	for(int i = 1; i <= n; i++) {
		if(col_min[colors[i]] > wts[i]) {
			indices[colors[i]] = i;
			col_min[colors[i]] = wts[i];
		}
		// col_min[colors[i]] = min(col_min[colors[i]], wts[i]);
	}
	LL minim = INF, s_minim = INF;
	for(int i = 1; i <= n; i++) {
		if(minim > col_min[i]) {
			s_minim = minim;
			minim = col_min[i];
		} else if(s_minim > col_min[i]) {
			s_minim = col_min[i];
		}
		if(col_min[i] < INF) {
			total.push_back({col_min[i], indices[i]});
		}
	}
	for(int i = 1; i <= n; i++) {
		sort(adj[i].begin(), adj[i].end());
	}
	for(int c = 1; c <= n; c++) {
		int idx = 0;
		while(idx + 1 < adj[c].size()) {
			if(adj[c][0].F + adj[c][idx+1].F <= X) {
				tester.merge(adj[c][0].S, adj[c][idx+1].S);
			} else break;
			idx++;
		}
	}
	sort(total.begin(), total.end());
	int idx = 0;
	while(idx + 1 < total.size()) {
		if(total[0].F + total[idx+1].F <= Y) {
			tester.merge(total[0].S, total[idx+1].S);
		} else break;
		idx++;
	}
	for(int i = 1; i <= n; i++) {
		for(auto &elem: adj[i]) {
			LL con = minim;
			if(col_min[i] == minim) {
				con = s_minim;
			}
			if(con + wts[elem.S] <= Y) {
				tester.merge(indices[i], elem.S);
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		int p = tester.find_root(i);
		in_that[p].push_back(i);
	}
	LL res = 1;
	for(int i = 1; i <= n; i++) {
		if(in_that[i].size() > 0) {
			res *= fact[in_that[i].size()];
			res %= mod;
			LL den = 1;
			for(auto &elem: in_that[i]) {
				cnt[colors[elem]]++;
				den = (den * cnt[colors[elem]]) % mod;
			}
			for(auto &elem: in_that[i]) {
				cnt[colors[elem]] = 0;
			}
			// cout << den << '\n';
			res *= modinv(den, mod);
			res %= mod;
		}
	}
	printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 55024