// Original C++ solution (slower):
#include <algorithm>

#include <cstdio>

#include <vector>

using namespace std;



const int N = 2e5 + 10;

const int MOD = 1e9 + 7;



int n, x, y, c[N], w[N], Min1, Min2;

int f[N], cnt[N], Min[N];

vector<int> v[N];



int qpow(int a, int b) {

	int ans = 1;

	for(; b; b >>= 1, a = a * 1ll * a % MOD)

		if(b & 1) ans = ans * 1ll * a % MOD;

	return ans;

}



int get(const int &u) {

	return u == f[u] ? u : f[u] = get(f[u]);

}

void unite(int u, int v) {

	(u = get(u)) != (v = get(v)) ? f[v] = u : 0;

}



int main() {

	scanf("%d%d%d", &n, &x, &y);

	

	static int fac[N] = {1}, fav[N];

	for(int i = 1; i <= n; i ++) 

		fac[i] = fac[i - 1] * 1ll * i % MOD;

	fav[n] = qpow(fac[n], MOD - 2);

	for(int i = n; i >= 1; i --)

		fav[i - 1] = fav[i] * 1ll * i % MOD;

	

	w[0] = 1 << 30;

	for(int i = 1; i <= n; i ++) {

		scanf("%d%d", c + i, w + i);

		if(w[i] < w[Min[c[i]]]) Min[c[i]] = i;

	}



	for(int i = 1; i <= n; i ++) if(Min[i]) {

		if(w[Min[i]] < w[Min1]) Min2 = Min1, Min1 = Min[i];

		else if(w[Min[i]] < w[Min2]) Min2 = Min[i];

	}



	for(int i = 1; i <= n; i ++) f[i] = i;

	for(int i = 1; i <= n; i ++) {

		if(w[Min[c[i]]] + w[i] <= x) unite(Min[c[i]], i);

		if(Min2 && c[Min2] != c[i] && w[Min2] + w[i] <= y) unite(Min2, i);

		if(Min1 && c[Min1] != c[i] && w[Min1] + w[i] <= y) unite(Min1, i);

	}

	int ans = 1;

	for(int i = 1; i <= n; i ++) v[get(i)].push_back(c[i]);

	

	for(int i = 1; i <= n; i ++) if(f[i] == i) {

		int size = v[i].size();

		ans = ans * 1ll * fac[size] % MOD;

		for(int j = 0; j < size; j ++) cnt[v[i][j]] ++;

		for(int j = 0; j < size; j ++) if(cnt[v[i][j]]) {

			ans = ans * 1ll * fav[cnt[v[i][j]]] % MOD;

			cnt[v[i][j]] = 0;

		}

	}

	printf("%d\n", ans);

	return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

using namespace std;



const int MAXN = 200000;

const int MOD = int(1E9) + 7;

const int INF = (1<<30);



int pow_mod(int b, int p) {

	int ret = 1;

	for(int i=p;i;i>>=1,b=1LL*b*b%MOD)

		if( i & 1 ) ret = 1LL*ret*b%MOD;

	return ret;

}



int fct[MAXN + 5], ifct[MAXN + 5];

void init() {

	fct[0] = 1;

	for(int i=1;i<=MAXN;i++)

		fct[i] = 1LL*i*fct[i-1]%MOD;

	ifct[MAXN] = pow_mod(fct[MAXN], MOD - 2);

	for(int i=MAXN-1;i>=0;i--)

		ifct[i] = 1LL*ifct[i+1]*(i+1)%MOD;

}



int c[MAXN + 5], w[MAXN + 5], N, X, Y;

int mn[MAXN + 5], cnt[MAXN + 5];



int main() {

	init(), scanf("%d%d%d", &N, &X, &Y);

	for(int i=1;i<=N;i++) mn[i] = INF;

	for(int i=1;i<=N;i++) {

		scanf("%d%d", &c[i], &w[i]);

		mn[c[i]] = min(mn[c[i]], w[i]);

	}

	for(int i=1;i<=N;i++)

		if( mn[c[i]] + w[i] <= X )

			w[i] = mn[c[i]];

	int fmn = -1, smn = -1;

	for(int i=1;i<=N;i++)

		if( mn[i] != INF ) {

			if( fmn == -1 || mn[fmn] > mn[i] )

				smn = fmn, fmn = i;

			else if( smn == -1 || mn[smn] > mn[i] )

				smn = i;

		}

	int tot = 0;

	for(int i=1;i<=N;i++) {

		if( c[i] == fmn ) {

			if( smn != -1 && w[i] + mn[smn] <= Y )

				cnt[c[i]]++, tot++;

		}

		else {

			if( w[i] + mn[fmn] <= Y )

				cnt[c[i]]++, tot++;

		}

	}

	int ans = fct[tot];

	for(int i=1;i<=N;i++)

		ans = 1LL*ans*ifct[cnt[i]]%MOD;

	printf("%d\n", ans);

}

// Fastest known solution for this problem: