// 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: 2.2114349818613785x):
#include <bits/stdc++.h>



#define MAXN 200005

#define INF 0x3f3f3f3f



typedef long long lint;



using namespace std;



const int mod = 1e9 + 7;

int n, x, y;

int c[MAXN], w[MAXN], mini[MAXN];

int sum[MAXN], amount;

int first, second, firstc;

lint fac[MAXN], inf[MAXN];



int read() {

    char c = getchar();

    int x = 0;

    while (!isdigit(c))

        c = getchar();

    while (isdigit(c)) {

        x = (x << 3) + (x << 1) + c - '0';

        c = getchar();

    }

    return x;

}



lint power(lint a, int b) {

    lint res = 1;

    while (b) {

        if (b & 1)

            res = res * a % mod;

        a = a * a % mod;

        b >>= 1;

    }

    return res;

}



void init() {

    fac[0] = inf[0] = 1;

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

        fac[i] = fac[i - 1] * i % mod;

    inf[n] = power(fac[n], mod - 2);

    for (int i = n - 1; i >= 1; --i)

        inf[i] = inf[i + 1] * (i + 1) % mod;

}



int main() {

//    freopen("15.txt", "r",stdin);

    n = read();

    x = read();

    y = read();

    init();

    memset(mini, 0x3f, sizeof(mini));

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

        c[i] = read();

        w[i] = read();

        mini[c[i]] = min(mini[c[i]], w[i]);

    }

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

        if (mini[c[i]] + w[i] <= x)

            w[i] = mini[c[i]];

    first = second = INF;

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

        if (mini[i] < first) {

            second = first;

            first = mini[i];

            firstc = i;

        }

        else if (mini[i] < second)

            second = mini[i];

//    printf("%d %d\n", first, second);

    if (first + second <= y)

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

            if (c[i] == firstc && w[i] != first && w[i] + second <= y)

                w[i] = first;

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

        if (c[i] == firstc && w[i] == first) {

//            cout << "first: " << i << endl;

            ++sum[c[i]];

            ++amount;

        }

        else if (c[i] != firstc && w[i] + first <= y) {

//            cout << "second: " << i << endl;

            ++sum[c[i]];

            ++amount;

        }

    lint res = fac[amount];

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

        res = res * inf[sum[i]] % mod;

    printf("%lld\n", res);

}