#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v, w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; int INF = INT_MAX / 2; ll extgcd(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = (a >= 0) ? 1 : -1; y = 0; return abs(a); } else { ll res = extgcd(b, a % b, y, x); y -= (a / b) * x; return res; } } ll mod_inverse(ll a, ll m) { ll x, y; extgcd(a, m, x, y); return (m + x % m) % m; } vector f(100001), fi(100001); ll c(int n, int k) { return f[n] * fi[k] % MOD * fi[n - k] % MOD; } int main() { f[0] = fi[0] = 1; for (int i = 1; i <= 100000; i++) { f[i] = (f[i - 1] * i) % MOD; fi[i] = mod_inverse(f[i], MOD); } int T; cin >> T; for (int t = 1; t <= T; t++) { map m; int n; cin >> n; for (int i = 0; i < n; i++) { int A; scanf("%d", &A); m[A]++; } ll hoge = 1; for (map::iterator it = m.begin(); it != m.end(); it++) { int x = it->second; hoge = (hoge * f[x]) % MOD; } hoge = mod_inverse(hoge, MOD); int p = 0; ll sum = 0; for (map::iterator it = m.begin(); it != m.end(); it++) { int x = it->second, A = it->first; int q = n - p - x; ll ans = c(n, p); ans = ans * f[p] % MOD; ans = ans * f[q] % MOD; ans = ans * hoge % MOD; ans = ans * f[x] % MOD; for (int y = 0; y < x; y++) { ll _ans = ans * c(q + y, y) % MOD; sum = (sum + _ans * A % MOD) % MOD; } p += x; } printf("Case #%d: %d\n", t, sum); } }