// Slower C++ solution:
#include <bits/stdc++.h>

#define reg register



using namespace std;



typedef long long ll;

const int maxn = 200005;

const int mod = 1e9 + 7;

const int INF = 0x7f7f7f7f;



inline int read() {

    reg int s = 0, t = 0; reg char ch = getchar();

    while (!isdigit(ch)) t |= ch == '-', ch = getchar();

    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();

    return t ? -s : s;

}



int n, x, y, ans = 1, sum;

int Size[maxn], fact[maxn], inv[maxn];

int c[maxn], w[maxn];

struct Edge { int to, nxt; } p[maxn << 3];

int minpos[maxn], minval[maxn];

bool used[maxn];



int cnt, head[maxn];

inline void addedge(reg int u, reg int v) {

    p[++cnt].to = v, p[cnt].nxt = head[u], head[u] = cnt;

    p[++cnt].to = u, p[cnt].nxt = head[v], head[v] = cnt;

}



inline void dfs(reg int u) {

    used[u] = true;

    for (reg int i = head[u]; i; i = p[i].nxt)

        if (!used[p[i].to]) dfs(p[i].to);

}



inline void build_same() {

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

        if (i != minpos[c[i]] && w[i] + minval[c[i]] <= x) addedge(i, minpos[c[i]]);

}



inline void build_diff() {

    int First, Second, FirstVal = INF, SecondVal = INF;

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

        if (w[i] < FirstVal) FirstVal = w[i], First = i;

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

        if (w[i] < SecondVal && c[i] != c[First]) SecondVal = w[i], Second = i;

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

        if (i == First) continue;

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

        if (SecondVal != INF && c[i] != c[Second] && w[i] + w[Second] <= y) addedge(i, Second);

    }

    dfs(First);

}



inline int mod_pow(reg int a, reg int b) {

    reg int ans = 1;

    while (b) {

        if (b & 1) ans = 1LL * ans * a % mod;

        b >>= 1, a = 1LL * a * a % mod;

    }

    return ans;

}



inline int calc(reg int x, reg int y) {

    return 1LL * fact[x] * inv[y] % mod * inv[x - y] % mod;

}



inline void init() {

    memset(minval, 0x7f, sizeof(minval));

    fact[0] = 1; for (reg int i = 1; i < maxn; i++) fact[i] = 1LL * fact[i - 1] * i % mod;

    inv[maxn - 1] = mod_pow(fact[maxn - 1], mod - 2);

    for (reg int i = maxn - 2; i >= 0; i--) inv[i] = 1LL * inv[i + 1] * (1LL * i + 1LL) % mod;

}



int main() {

    ios::sync_with_stdio(false);

    n = read(), x = read(), y = read(), init();

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

        c[i] = read(), w[i] = read();

        if (minval[c[i]] > w[i]) minval[c[i]] = w[i], minpos[c[i]] = i;

    }

    build_same(), build_diff();

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

        if (used[i]) Size[c[i]]++;

    for (reg int i = 1; i <= n; i++) sum += Size[i];

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

        if (Size[i]) ans = 1LL * ans * calc(sum, Size[i]) % mod, sum -= Size[i];

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.962681500232132x):
#include<bits/stdc++.h>

using namespace std;

const int P=1e9+7,N=2e5+7;

int c[N],w[N],d[N],f[N],iv[N],fc[N],fciv[N];

int main(){

	int n,x,y,i,j,t=0,mn=2e9,mn2=2e9,ans=1;

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

	memset(d,63,n+1<<2);

	for(i=1;i<=n;++i)scanf("%d%d",c+i,w+i),d[c[i]]=min(d[c[i]],w[i]);

	for(i=1;i<=n;++i)if(d[i]<mn)mn2=mn,mn=d[i];else if(d[i]<mn2)mn2=d[i];

	if(mn+mn2>y)return puts("1"),0;

	fc[1]=iv[1]=fciv[1]=1;

	for(i=2;i<=n;++i)iv[i]=(P-P/i)*1ll*iv[P%i]%P,fc[i]=fc[i-1]*1ll*i%P,fciv[i]=fciv[i-1]*1ll*iv[i]%P;

	for(i=1;i<=n;++i)if((w[i]+d[c[i]]<=x)||(w[i]+(d[c[i]]==mn?mn2:mn)<=y))++f[c[i]];

	for(i=1;i<=n;++i)if(d[i]+mn<=y)t+=f[i],ans=ans*1ll*fciv[f[i]]%P;

	printf("%d",ans*1ll*fc[t]%P);

	return 0;

}