#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;
}