#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"

const int MAXN = 4e5 + 10;
const int MOD = 1e9 + 7;

void add(int& x, int y) {
	((x += y) >= MOD) && (x -= MOD);
}

int mul(int x, int y) {
	return x * 1ll * y % MOD;
}

int mpow(int a, int p) {
	int res = 1;
	for (; p > 0; a = mul(a, a), p >>= 1) {
		if  (p & 1) {
			res = mul(res, a);
		}
	}
	return res;
}

int inv(int x) {
	assert(x);
	int y = mpow(x, MOD - 2);
	assert(mul(x, y) == 1);
	return y;
}

int n, x, y;
int c[MAXN];
int w[MAXN];

bool read() {
	if  (scanf("%d%d%d", &n, &x, &y) < 3) {
		return 0;
	}
	forn(i, n) {
		scanf("%d%d", &c[i], &w[i]);
		--c[i];
	}
	return 1;
}

int fact[MAXN];
int inv_fact[MAXN];

void precalc() {
	fact[0] = 1;
	for (int i = 1; i < MAXN; ++i) {
		fact[i] = mul(i, fact[i - 1]);
	}
	forn(i, MAXN) {
		inv_fact[i] = inv(fact[i]);
	}
}

int C(int n, int k) {
	return mul(fact[n], mul(inv_fact[n - k], inv_fact[k]));
}

struct DSU {
	vi par;

	DSU(int n = 0) {
		par.assign(n, -1);
	}

	int get(int x) {
		return par[x] < 0 ? x : par[x] = get(par[x]);
	}

	void unite(int x, int y) {
		x = get(x);
		y = get(y);
		if  (x == y) {
			return;
		}
		if  (-par[x] < -par[y]) {
			swap(x, y);
		}
		par[x] += par[y];
		par[y] = x;
	}
};

vii ws[MAXN];

int get(vi cs) {
	sort(all(cs));

	int ans = 1;
	int have = 0;
	for (int i = 0, j = 0; i < sz(cs); i = j) {
		while (j < sz(cs) && cs[i] == cs[j]) {
			++j;
		}

		int len = j - i;
		ans = mul(ans, C(have + len, len));
		have += len;
	}

	return ans;
}

int solve() {
	forn(i, n) {
		ws[i].clear();
	}
	forn(i, n) {
		ws[c[i]].pb(mp(w[i], i));
	}
	forn(c, n) {
		sort(all(ws[c]));
	}

	DSU dsu(n);
	forn(c, n) {
		if  (ws[c].empty()) {
			continue;
		}
		for (int i = 1; i < sz(ws[c]) && ws[c].front().fst + ws[c][i].fst <= x; ++i) {
			dsu.unite(ws[c].front().snd, ws[c][i].snd);
		}
	}


	vii cs;
	forn(c, n) {
		if  (!ws[c].empty()) {
			cs.pb(mp(ws[c].front().fst, c));
		}
	}
	sort(all(cs));

	forn(i, min(2, sz(cs))) {
		int C = cs[i].snd;
		int W = cs[i].fst;
		forn(c, n) {
			if  (c == C) {
				continue;
			}
			forn(i, sz(ws[c])) {
				if  (W + ws[c][i].fst > y) {
					break;
				}
				dsu.unite(ws[C].front().snd, ws[c][i].snd);
			}
		}
	}

	vvi who(n);
	forn(v, n) {
		who[dsu.get(v)].pb(c[v]);
	}
	int ans = 1;
	forn(c, n) {
		ans = mul(ans, get(who[c]));
	}
	return ans;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	precalc();

	while (read()) {
		cout << solve() << endl;
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 31736