#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int parent[(int)(2e5+3)];
int size[(int)(2e5+3)];
int color_num[(int)(2e5+3)];

int find(int a){
	//cout<<parent[a]<<endl;
	if(parent[a] == a) return a;
	return parent[a] = find(parent[a]);
}

void unite(int a, int b){
	//cout<<a<<" "<<b<<endl;
	if(find(a) == find(b)) return;
	int pa = find(a);
	int pb = find(b);
	size[pa] += size[pb];
	parent[pb] = parent[pa];
	return;
}

int main(void){
	int n,x,y;
	cin>>n>>x>>y;
	vector<pair<int,pair<int,int>>> ball;
	vector<pair<int,pair<int,int>>> order;
	rep(i,n){
		int c,w;
		cin>>c>>w;
		ball.push_back(pair<int,pair<int,int>>{c,pair<int,int>{w,i}});
		order.push_back(pair<int,pair<int,int>>{w,pair<int,int>{c,i}});
	}
	rep(i,n){
		parent[i] = i;
		size[i] = 1;
		color_num[i] = 0;
	}
	if(n==1){
		cout<<1<<endl;
		return 0;
	}
	sort(all(order));
	sort(all(ball));
	int maw = order[0].first;
	int mac = order[0].second.first;
	int mai = order[0].second.second;
	int m2w = maw,m2c = mac, m2i = mai;
	int hoge = 1;
	while(hoge < n && order[hoge].second.first == mac){
		hoge++;
	}
	if(hoge < n){
		m2c = order[hoge].second.first;
		m2w = order[hoge].first;
		m2i = order[hoge].second.second;
	}
	int color = -1;
	int min_w = INF;
	int min_id = -1;
	rep(i,n){
		int ww = ball[i].second.first;
		int cc = ball[i].first;
		int id = ball[i].second.second;
		if(color != cc){
			color = cc;
			min_w = ww;
			min_id = id;
		}
		//cout<<"bb"<<endl;
		if(min_w + ww <= x){
			//cout<<"cc"<<endl;
			//cout<<id<<" "<<min_id<<endl;
			unite(id, min_id);
		}
		if(mac != color){
			if(maw + ww <= y){
				//cout<<"dd"<<endl;
				unite(id, mai);
			}
			
		}else{
			if(m2c != color && m2w + ww <= y){
				//cout<<"ee"<<endl;
				unite(id, m2i);
			}
		}
		//cout<<"aa"<<endl;
	}

	/*
	rep(i,n){
		cout<<find(i)<<" ";
	}
	cout<<endl;*/
	vector<int> shugo[(int)(2e5+3)];
	int bi = 0;
	while(bi < n){
		int col = ball[bi].first;
		int id = ball[bi].second.second;
		int pa = find(id);
		shugo[pa].push_back(col);
		int count = 0;
		while(bi < n && ball[bi].first == col && find(ball[bi].second.second) == pa){
			count++;
			bi++;
		}
		color_num[col] = count;
		while(bi < n && ball[bi].first == col){
			bi++;
		}
	}
	
	ll ans = 1;
	rep(i,n){
		if(shugo[i].size() == 0) continue;
		ll sum = 0, add = 1;
		rep(j,shugo[i].size()){
			int col = shugo[i][j];
			sum += color_num[col];
			add *= mpow(kaijo(color_num[col]), MOD-2);
			add %= MOD;
		}
		add *= kaijo(sum);
		add %= MOD;
		ans *= add;
		ans %= MOD;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 18980