#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1e9+7;
ll fac[1009],inverse[1009];
void factorial(){
fac[0]=fac[1]=1;
for(int i =2;i<=1000;i++){
fac[i]= (fac[i-1]*i)%mod;
}
}
ll power(ll a,ll b){
if(b==0)return 1;
ll ans = 1;
if(b%2==1)ans = (ans%mod * a%mod)%mod;
ll t = power(a,b/2)%mod;
return (ans * (t%mod * t%mod)%mod)%mod;
}
void inv(){
for(int i = 0;i<=1000;i++){
inverse[i] = power(fac[i],mod-2);
}
}
ll nck(int n,int k){
ll a = fac[n]%mod;
ll b = power(fac[k],mod-2)%mod;
ll c = power(fac[n-k],mod-2)%mod;
return (((a * b)%mod) * c)%mod;
}
ll npk(int n,int k){
ll a = fac[n]%mod;
ll b = inverse[n-k]%mod;
return (a*b)%mod;
}
int main(){
int t;
cin>>t;
int Case = 0;
factorial();
inv();
while(t--){
Case++;
int x,y;
cin>>x>>y;
vector<ll> a(x+1);
for(int i = 1 ; i <=x ;i++){
a[i] = nck(x,i);
}
a[0]=1;
vector<ll> b(y+1);
for(int i = 1 ;i<=y ;i++){
b[i]=nck(y,i);
}
b[0]=1;
ll injective = 0;
for(int i = 1;i<=x;i++){
ll ti = 0;
for(int j = i+1;j<=y;j++){
ti = (ti + ( (npk(j,i)) * (b[j]) )%mod)%mod;
}
injective = (injective + (ti * a[i])%mod)%mod;
}
long long subjective = 0;
for(int i = 1;i<=y;i++){
ll ti = 0;
ll w = fac[i];
for(int j = i+1;j<=x;j++){
ti = ti + (( ((a[j] * w)%mod) * power(i,j-i))%mod);
}
subjective = (subjective + ((ti * b[i])%mod))%mod;
}
long long bijective = 0;
for(int i = 1 ; i<=min(x,y);i++ ){
bijective = (bijective + ( ( ((a[i]%mod)*(b[i]%mod))%mod )*(fac[i]%mod))%mod )%mod;
}
long long tot = 0;
for(int i = 1; i <= x ; i++){
for(int j= 1;j <=y; j++){
tot = (tot + (((power(j,i)*a[i])%mod)*b[j])%mod)%mod;
}
}
cout<<"Case "<<Case<<": ";
cout<<(injective%mod+bijective%mod)%mod<<" "<<(subjective%mod+bijective%mod)%mod<<" "<<
(bijective)%mod<<" "<<tot%mod<<'\n';
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBpbnQgbGw7CmxsIG1vZCA9IDFlOSs3OwpsbCBmYWNbMTAwOV0saW52ZXJzZVsxMDA5XTsKdm9pZCBmYWN0b3JpYWwoKXsKCWZhY1swXT1mYWNbMV09MTsKCWZvcihpbnQgaSA9MjtpPD0xMDAwO2krKyl7CgkJZmFjW2ldPSAoZmFjW2ktMV0qaSklbW9kOwoJfQp9CgpsbCBwb3dlcihsbCBhLGxsIGIpewogICAgaWYoYj09MClyZXR1cm4gMTsKICAgIGxsIGFucyA9IDE7CiAgICBpZihiJTI9PTEpYW5zID0gKGFucyVtb2QgKiBhJW1vZCklbW9kOwogICAgbGwgdCA9IHBvd2VyKGEsYi8yKSVtb2Q7CiAgICByZXR1cm4gKGFucyAqICh0JW1vZCAqIHQlbW9kKSVtb2QpJW1vZDsKfQoKIHZvaWQgaW52KCl7Cglmb3IoaW50IGkgPSAwO2k8PTEwMDA7aSsrKXsKCQlpbnZlcnNlW2ldID0gcG93ZXIoZmFjW2ldLG1vZC0yKTsKCX0KfQpsbCBuY2soaW50IG4saW50IGspewoJbGwgYSA9IGZhY1tuXSVtb2Q7CglsbCBiID0gcG93ZXIoZmFjW2tdLG1vZC0yKSVtb2Q7CglsbCBjID0gcG93ZXIoZmFjW24ta10sbW9kLTIpJW1vZDsKCXJldHVybiAoKChhICogYiklbW9kKSAqIGMpJW1vZDsKfQoKbGwgbnBrKGludCBuLGludCBrKXsKCWxsIGEgPSBmYWNbbl0lbW9kOwoJbGwgYiA9IGludmVyc2Vbbi1rXSVtb2Q7CglyZXR1cm4gKGEqYiklbW9kOwoKfQppbnQgbWFpbigpewoJaW50IHQ7CgljaW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