#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdio>
using namespace std;
typedef unsigned long long uint64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5, P = 1e9+7;
int n, a, b, c[N], w[N], s[N], minw[N], all, u, v;
uint64 fac[N], ans, inv[N], ifac[N];
int main()
{
    n = read(), a = read(), b = read();
    fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
    for(int i = 1; i <= n; ++i) 
    {
        c[i] = read(), w[i] = read();
        if(!u||w[u] > w[i]) v = u, u = i;
        else if(!v||w[v] > w[i]) v = i;
        if(!minw[c[i]]) minw[c[i]] = w[i];
        else if(minw[c[i]] > w[i]) minw[c[i]] = w[i];
    }
    for(int i = 1, j = 2; i <= n; ++i, ++j)
    {
        inv[j] = inv[P%j]*(P-P/j)%P, fac[j] = fac[j-1]*j%P, ifac[j] = ifac[j-1]*inv[j]%P;
        if(w[i]+minw[c[i]] <= a) w[i] = minw[c[i]];
        if((c[u] == c[i]&&w[i]+w[v] <= b)||(c[u] != c[i]&&w[i]+w[u] <= b)) ++s[c[i]], ++all;
    }
    ans = fac[all];
    for(int i = 1; i <= n; ++i) ans = ans*ifac[s[i]]%P;
    printf("%llu\n", ans);
    return 0;
}