Reference: CF2 GYM 100 548 Color (2014ACM Xi'an game field F. Problem) codeforces Gym 100548F Color (+ number of combinations of inclusion and exclusion)
Idea: You can refer to the idea of a blog, it is easy to understand
Caveats: Because data is large so believe it will burst, it is best to have a long long
ll ans=0;
int flag=1;
for(int i=k;i>=1;i--)
ans=(ans+(1ll*flag*i*qpow(i-1,n-1)%mod*c[i]%mod)+mod)%mod,flag=-flag;
/*这个地方如果不乘1ll就会爆,如果不乘1ll的话,因为flag是int,所以乘起来就是按int来乘的*/
Code:
// Created by CAD on 2019/8/11.
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int, int>;
using piii=pair<pair<int, int>, int>;
using ll=long long;
const int mod= 1e9+7;
const int maxn=1e6+5;
int c[1000005];
int inv[1000005];
ll qpow(ll x,ll n)
{
ll re=1;
while(n>0)
{
if(n&1) re=(re*x)%mod;
n>>=1;
x=x*x%mod;
}
return re;
}
void init_inv()
{
inv[1]=1;
for(int i=2;i<maxn;++i)
inv[i]=ll(mod-mod/i)*inv[mod%i]%mod;
}
int k;
void init_C(ll n)
{
c[0]=1;
for(int i=1;i<=k;++i)
c[i]=c[i-1]*(n-i+1)%mod*inv[i]%mod;
}
ll n,m;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
init_inv();
int t; cin>>t;
for(int Case=1;Case<=t;Case++)
{
cin>>n>>m>>k;
init_C(k);
ll ans=0;
int flag=1;
for(int i=k;i>=1;i--)
ans=(ans+(1ll*flag*i*qpow(i-1,n-1)%mod*c[i]%mod)+mod)%mod,flag=-flag;
init_C(m);
cout<<"Case #"<<Case<<": "<<ans*c[k]%mod<<endl;
}
return 0;
}