#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================
vi g[N];
int a[N], col[N], w[N]; ll fac[N], inv[N];
bool f(int x, int y){
return w[x] < w[y];
}
map<int, int> cnt[N];
int par[N], sz[N];
int rep(int x){
if(x == par[x]) return x;
return par[x] = rep(par[x]);
}
void unite(int x, int y){
x = rep(x);
y = rep(y);
if(x == y) return;
if(sz[x]>sz[y]) swap(x, y);
par[x] = y;
sz[y] += sz[x] == sz[y];
}
int minof[N];
int tot[N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i,n,k,j,x,y;
fac[0] = inv[0] = 1;
Fo(i, 1, N){
fac[i] = (i*fac[i-1])%mod;
inv[i] = (mpow(i, mod-2)*inv[i-1])%mod;
par[i] = i;
sz[i] = 1;
}
cin >> n >> x >> y;
Fo(i, 1, n+1){
cin >> col[i] >> w[i];
g[col[i]].pb(i);
}
Fo(i, 1, n+1){
//uniting of color[i]
minof[i] = mod;
if(g[i].empty()) continue;
sort(all(g[i]), f);
int base = g[i][0];
minof[i] = w[base];
for(int v: g[i]){
if(w[v]+w[base] <= x) unite(v, base);
}
}
minof[0] = mod;
int mn1, mn2 = 0;
mn1 = col[1];
Fo(i, 1, n+1){
if(minof[col[i]] <= minof[mn1])
mn1 = col[i];
}
Fo(i, 1, n+1){
if(col[i] != mn1) mn2 = col[i];
}
Fo(i, 1, n+1){
if(col[i]!=mn1 and minof[col[i]] <= minof[mn2])
mn2 = col[i];
}
int pos1, pos2 = -1;
Fo(i, 1, n+1){
if(col[i] == mn1 and w[i] == minof[mn1]) pos1 = i;
if(col[i] == mn2 and w[i] == minof[mn2]) pos2 = i;
}
//mn1, mn2 colors ki hai minimum
Fo(i, 1, n+1){
if(col[i] != mn1){
if(w[i]+minof[mn1] <= y) unite(i, pos1);
}
else if (pos2!=-1){
if(w[i]+minof[mn2] <= y) unite(i, pos2);
}
}
Fo(i, 1, n+1){
tot[rep(i)]++;
cnt[rep(i)][col[i]]++;
}
ll ans = 1, cur = 0;
Fo(i, 1, n+1){
if(i == rep(i)){
ans *= fac[tot[i]];
ans %= mod;
for(auto it: cnt[i]){
ans *= inv[it.S];
ans %= mod;
}
}
}
cout << ans << endl;
return 0;
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgZ2MgZ2V0Y2hhcl91bmxvY2tlZAojZGVmaW5lIGZvKGksbikgZm9yKGk9MDtpPG47aSsrKQojZGVmaW5lIEZvKGksayxuKSBmb3IoaT1rO2s8bj9pPG46aT5uO2s8bj9pKz0xOmktPTEpCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgc2koeCkJc2NhbmYoIiVkIiwmeCkKI2RlZmluZSBzbCh4KQlzY2FuZigiJWxsZCIsJngpCiNkZWZpbmUgc3MocykJc2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