#include <bits/stdc++.h>
using namespace std;
#define ll int
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define inf (1LL << 62)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9 + 7, last = (1LL << 27);
const ll block = 1e3;
ll mult[42][last/block+10];
int main()
{
for(ll i = 2; i <= 40; i++) {
long long mul = 1;
for(ll j = i, k = 1; j <= last; j += i, k++) {
mul = (mul * (1 + j)) % mod;
ll b = k / block;
mult[i][b] = mul;
}
}
ll t, cs = 0;
cin >> t;
while(t--) {
ll n, k;
si(k), si(n);
ll c = n / k, b = c / block;
long long mul = 1;
if(b > 0) mul = mult[k][b-1];
for(ll i = b*block; i <= c; i++)
mul = (mul * (1 + i*k)) % mod;
pf("Case %d: %lld\n", ++cs, mul);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGxsIGludAojZGVmaW5lIHVsbCB1bnNpZ25lZCBsb25nIGxvbmcKI2RlZmluZSBkZCBkb3VibGUKI2RlZmluZSBsZCBsb25nIGRvdWJsZQojZGVmaW5lIHNsKG4pIHNjYW5mKCIlbGxkIiwgJm4pCiNkZWZpbmUgc2kobikgc2NhbmYoIiVkIiwgJm4pCiNkZWZpbmUgc2Qobikgc2NhbmYoIiVsZiIsICZuKQoj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