#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int, int > ii;
const int N = 55;
const int mod = 1e9 + 7;
inline int add(int x, int y) {
return x + y >= mod ? x + y - mod : x + y;
}
inline int mul(int x, int y) {
return (ll) x * y % mod;
}
inline int fe(int x, int k) {
int res = 1;
while(k) {
if(k & 1)
res = mul(res, x);
x = mul(x, x);
k >>= 1;
}
return res;
}
inline int dv(int x, int k) {
return mul(x, fe(k, mod - 2));
}
int n, s, e;
ii a[N];
int pw[N];
int dp[N][N][N][2];
#define UP 1
#define DOWN 2
#define LEFT 4
#define RIGHT 8
#define c(x, y) (!!(x&y))
int f(int x, int ms, int me, bool done) {
if(x > n)
return done;
int &r = dp[x][ms][me][done];
if(r != -1) return r;
if(x == s)
return r = f(x + 1, 0, me, done);
if(x == e)
return r = f(x + 1, ms, N - 1, done);
r = 0;
for(int i = 1; i < 16; i += i) {
bool d = done;
d |= x < s and c(i, UP) and ms <= a[x].second;
d |= x > s and c(i, LEFT) and ms >= a[x].second;
d |= x < e and c(i, DOWN) and me >= a[x].second;
d |= x > e and c(i, LEFT) and me <= a[x].second;
int nms = ms, nme = me;
if(x < s and c(i, RIGHT))
nms = min(nms, a[x].second);
if(x > s and c(i, UP))
nms = max(nms, a[x].second);
if(x < e and c(i, RIGHT))
nme = max(nme, a[x].second);
if(x > e and c(i, DOWN))
nme = min(nme, a[x].second);
r = add(r, f(x + 1, nms, nme, d));
}
return r;
}
void solve() {
scanf("%d %d %d", &n, &s, &e);
for(int i = 1; i <= n; i++) {
scanf("%d %d", &a[i].first, &a[i].second);
swap(a[i].first, a[i].second);
}
a[++n] = {s, 0};
a[++n] = {e, 1e9};
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++) {
if(a[i].second == 0)
s = i;
if(a[i].second == 1e9)
e = i;
}
vector < int > vx, vy;
for(int i = 1; i <= n; i++)
vx.push_back(a[i].first), vy.push_back(a[i].second);
sort(vx.begin(), vx.end());
vx.resize(unique(vx.begin(), vx.end()) - vx.begin());
sort(vy.begin(), vy.end());
vy.resize(unique(vy.begin(), vy.end()) - vy.begin());
for(int i = 1; i <= n; i++) {
a[i].first = lower_bound(vx.begin(), vx.end(), a[i].first) - vx.begin() + 1;
a[i].second = lower_bound(vy.begin(), vy.end(), a[i].second) - vy.begin() + 1;
}
memset(dp, -1, sizeof(dp));
printf("%d\n", f(1, N - 1, 0, 0));
}
int main() {
freopen("in2.txt", "r", stdin);
freopen("out.txt", "w", stdout);
int tt;
scanf("%d", &tt);
for(int t = 1; t <= tt; t++) {
printf("Case #%d: ", t);
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgcGFpciA8IGludCwgaW50ID4gaWk7Cgpjb25zdCBpbnQgTiA9IDU1Owpjb25zdCBpbnQgbW9kID0gMWU5ICsgNzsKCmlubGluZSBpbnQgYWRkKGludCB4LCBpbnQgeSkgewogIHJldHVybiB4ICsgeSA+PSBtb2QgPyB4ICsgeSAtIG1vZCA6IHggKyB5Owp9CgppbmxpbmUgaW50IG11bChpbnQgeCwgaW50IHkpIHsKICByZXR1cm4gKGxsKSB4ICogeSAlIG1vZDsKfQoKaW5saW5lIGludCBmZShpbnQgeCwgaW50IGspIHsKICBpbnQgcmVzID0gMTsKICB3aGlsZShrKSB7CiAgICBpZihrICYgMSkKICAgICAgcmVzID0gbXVsKHJlcywgeCk7CiAgICB4ID0gbXVsKHgsIHgpOwogICAgayA+Pj0gMTsKICB9CiAgcmV0dXJuIHJlczsKfQoKaW5saW5lIGludCBkdihpbnQgeCwgaW50IGspIHsKICByZXR1cm4gbXVsKHgsIGZlKGssIG1vZCAtIDIpKTsKfQoKaW50IG4sIHMsIGU7CmlpIGFbTl07CmludCBwd1tOXTsKaW50IGRwW05dW05dW05dWzJdOwoKI2RlZmluZSBVUCAxCiNkZWZpbmUgRE9XTiAyCiNkZ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