#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define SZ(v) int((v).size())
vi a;
ll dp[11][11][2][2][11];
int vis[11][11][2][2][11], vid;
ll go(int i, int last, bool lo, bool nonzero, int need) {
if (i == SZ(a))
return need == 0;
ll &ret = dp[i][last + 1][lo][nonzero][need];
if (vis[i][last + 1][lo][nonzero][need] == vid) return ret;
vis[i][last + 1][lo][nonzero][need] = vid;
ret = 0;
int EN = lo ? 9 : a[i];
for (int j = 0; j <= EN; ++j) {
ret += go(i + 1, last, j != EN || lo, nonzero || j, need);
if (j > last && need && (nonzero || j))
ret += go(i + 1, j, j != EN || lo, 1, need - 1);
}
return ret;
}
void build(int s) {
++vid;
a.clear();
while (s) {
a.push_back(s % 10);
s /= 10;
}
reverse(all(a));
}
pair<int, ll> solve(int s, int e) {
vector<ll> lids(10);
build(e);
for (int i = 1; i < 10; ++i) {
lids[i] += go(0, -1, 0, 0, i);
}
build(s - 1);
for (int i = 1; i < 10; ++i) {
lids[i] -= go(0, -1, 0, 0, i);
}
for (int i = 9; i >= 1; --i) {
if (lids[i]) return {i, lids[i]};
}
return {0, 1};
}
void MAIN(int tc) {
int s, e;
scanf("%d%d", &s, &e);
auto ret = solve(s, e);
printf("Case %d: %d %lld\n", tc, ret.F, ret.S);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef CLION
freopen("in", "rt", stdin);
#endif
int nTests;
scanf("%d", &nTests);
for (int tc = 1; tc <= nTests; ++tc) {
MAIN(tc);
}
}
I2luY2x1ZGUgImJpdHMvc3RkYysrLmgiCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdXNpbmcgbGwgPSBsb25nIGxvbmc7CnVzaW5nIHZpID0gdmVjdG9yPGludD47CnVzaW5nIHBpaSA9IHBhaXI8aW50LCBpbnQ+OwojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIGFsbCh2KSAodikuYmVnaW4oKSwgKHYpLmVuZCgpCiNkZWZpbmUgU1oodikgaW50KCh2KS5zaXplKCkpCgp2aSBhOwpsbCBkcFsxMV1bMTFdWzJdWzJdWzExXTsKaW50IHZpc1sxMV1bMTFdWzJdWzJdWzExXSwgdmlkOwpsbCBnbyhpbnQgaSwgaW50IGxhc3QsIGJvb2wgbG8sIGJvb2wgbm9uemVybywgaW50IG5lZWQpIHsKICAgIGlmIChpID09IFNaKGEpKQogICAgICAgIHJldHVybiBuZWVkID09IDA7CgogICAgbGwgJnJldCA9IGRwW2ldW2xhc3QgKyAxXVtsb11bbm9uemVyb11bbmVlZF07CiAgICBpZiAodmlzW2ldW2xhc3QgKyAxXVtsb11bbm9uemVyb11bbmVlZF0gPT0gdmlkKSByZXR1cm4gcmV0OwogICAgdmlzW2ldW2xhc3QgKyAxXVtsb11bbm9uemVyb11bbmVlZF0gPSB2aWQ7CiAgICByZXQgPSAwOwogICAgaW50IEVOID0gbG8gPyA5IDogYVtpXTsKICAgIGZvciAoaW50IGogPSAwOyBqIDw9IEVOOyArK2opIHsKICAgICAgICByZXQgKz0gZ28oaSArIDEsIGxhc3QsIGogIT0gRU4gfHwgbG8sIG5vbnplcm8gfHwgaiwgbmVlZCk7CgogICAgICAgIGlmIChqID4gbGFzdCAmJiBuZWVkICYmIChub256ZXJvIHx8IGopKQogICAgICAgICAgICByZXQgKz0gZ28oaSArIDEsIGosIGogIT0gRU4gfHwgbG8sIDEsIG5lZWQgLSAxKTsKICAgIH0KICAgIHJldHVybiByZXQ7Cn0Kdm9pZCBidWlsZChpbnQgcykgewogICAgKyt2aWQ7CiAgICBhLmNsZWFyKCk7CiAgICB3aGlsZSAocykgewogICAgICAgIGEucHVzaF9iYWNrKHMgJSAxMCk7CiAgICAgICAgcyAvPSAxMDsKICAgIH0KICAgIHJldmVyc2UoYWxsKGEpKTsKfQpwYWlyPGludCwgbGw+IHNvbHZlKGludCBzLCBpbnQgZSkgewogICAg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