#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 mulmod(ll a,ll b){
return ( (a%mod) * (b%mod) )%mod;
}
ll plusmod(ll a,ll b){
return ( (a%mod) + (b%mod) )%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(){
inverse[0] = inverse[1] = 1;
for(int i = 2;i<=1000;i++){
inverse[i] = mulmod(inverse[i-1], power(i,mod-2));
}
}
ll nck(int n,int k){
ll a = fac[n]%mod;
ll b = inverse[k];
ll c = inverse[n-k];
return mulmod( mulmod(a,b),c);
}
ll npk(int n,int k){
ll a = fac[n];
ll b = inverse[n-k];
return mulmod(a,b);
}
int main(){
int t;
cin>>t;
int Case = 0;
factorial();
inv();
while(t--){
Case++;
int x,y;
cin>>x>>y;
vector<ll> xck(x+1);
for(int i = 1 ; i <=x ;i++){
xck[i] = nck(x,i);
}
xck[0]=1;
vector<ll> yck(y+1);
for(int i = 1 ;i<=y ;i++){
yck[i]=nck(y,i);
}
yck[0]=1;
ll injective = 0;
for(int i = 1;i<=x;i++){
ll temp = 0;
for(int j = i+1;j<=y;j++){
temp = plusmod( temp, mulmod(npk(j,i),yck[j]) );
}
injective = plusmod(injective, mulmod(temp, xck[i]) );
}
long long subjective = 0;
for(int i = 1;i<=y;i++)
{
ll temp = 0;
ll w = fac[i];
for(int j = i+1;j<=x;j++){
temp = plusmod(temp, mulmod(mulmod(xck[j],w), power(i,j-i) ) );
}
subjective = plusmod(subjective, mulmod(temp,yck[i]) );
}
long long bijective = 0;
for(int i = 1 ; i<=min(x,y);i++ ){
bijective = plusmod(bijective, mulmod( mulmod(xck[i],yck[i]), fac[i] ) );
}
long long tot = 0;
for(int i = 1; i <= x ; i++){
for(int j= 1;j <=y; j++){
tot = plusmod(tot, mulmod( mulmod(xck[i],power(j,i)), yck[j]) );
}
}
cout<<"Case "<<Case<<": ";
cout<<plusmod(injective,bijective)<<" "<<plusmod(subjective,bijective)<<" "<<
bijective<<" "<<tot<<'\n';
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBpbnQgbGw7CmxsIG1vZCA9IDFlOSs3OwpsbCBmYWNbMTAwOV0saW52ZXJzZVsxMDA5XTsKdm9pZCBmYWN0b3JpYWwoKXsKCWZhY1swXT1mYWNbMV09MTsKCWZvcihpbnQgaSA9MjtpPD0xMDAwO2krKyl7CgkJZmFjW2ldPSAoZmFjW2ktMV0qaSklbW9kOwoJfQp9CmxsIG11bG1vZChsbCBhLGxsIGIpewoJcmV0dXJuICggKGElbW9kKSAqIChiJW1vZCkgKSVtb2Q7Cn0KbGwgcGx1c21vZChsbCBhLGxsIGIpewoJcmV0dXJuICggKGElbW9kKSArIChiJW1vZCkgKSVtb2Q7Cn0KCmxsIHBvd2VyKGxsIGEsbGwgYil7CiAgICBpZihiPT0wKXJldHVybiAxOwogICAgbGwgYW5zID0gMTsKICAgIGlmKGIlMj09MSlhbnMgPSAoYW5zJW1vZCAqIGElbW9kKSVtb2Q7CiAgICBsbCB0ID0gcG93ZXIoYSxiLzIpJW1vZDsKICAgIHJldHVybiAoYW5zICogKHQlbW9kICogdCVtb2QpJW1vZCklbW9kOwp9Cgogdm9pZCBpbnYoKXsKCWludmVyc2VbMF0gPSBpbnZlcnNlWzFdID0gMTsKCWZvcihpbnQgaSA9IDI7aTw9MTAwMDtpKyspewoJCWludmVyc2VbaV0gPSBtdWxtb2QoaW52ZXJzZVtpLTFdLCBwb3dlcihpLG1vZC0yKSk7Cgl9Cn0KbGwgbmNrKGludCBuLGludCBrKXsKCWxsIGEgPSBmYWNbbl0lbW9k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